Skip to content

Commit

Permalink
update createMapview action in mapview store.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuGil committed Jun 19, 2024
1 parent ebc600c commit cbe5798
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions frontend/stores/mapview.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ export const useMapViewStore = defineStore('mapView', {
updateMapServiceUrl(mapServiceUrl) {
this.mapServiceUrl = mapServiceUrl
},
updateName(name) {
this.name = name
},
async createMapview() {
/**
* Create a new mapview in the backend with the current state of the store
*/

// TODO: create geometries and location collection
var location_url;
// create the location collection, if there are geometries
if (Object.keys(this.geometries).length !== 0) {
Expand All @@ -61,8 +65,11 @@ export const useMapViewStore = defineStore('mapView', {
'description': null }
}
)));

if (res.value) {
location_url = res.value.url
}

location_url = res.value.url
if (error.value) {
throw new Error('Error creating location collection //> ', error.value)
}
Expand All @@ -72,7 +79,7 @@ export const useMapViewStore = defineStore('mapView', {

const global = useGlobalStore()
const config = setRequestConfig({ method: 'POST', body: this.getFormattedBody })
const { data, error, refresh } = await useAsyncData(() => $cmsApi(`/map_views/`, config));
const { data, error, refresh } = await useAsyncData(() => $cmsApi(`/map-views/`, config));

if (error.value) {
let warnMessage = null
Expand All @@ -83,6 +90,12 @@ export const useMapViewStore = defineStore('mapView', {
global.warning(warnMessage)
return null
}

if (data.value) {
this.id = data.value.id
this.url = data.value.url
}

// Notification
global.succes('Map saved')
return { data: data?.value, refresh }
Expand Down

0 comments on commit cbe5798

Please sign in to comment.