activity: fix the on-the-fly POSTing of the location entity

This commit is contained in:
nobohan 2021-11-24 14:11:25 +01:00
parent d27f085ac9
commit 0bd0487801
2 changed files with 20 additions and 10 deletions

View File

@ -74,7 +74,6 @@ export default {
...concernedThirdPartiesLocation, ...concernedThirdPartiesLocation,
...response.results, ...response.results,
]; ];
console.log(this.locations);
if (window.default_location_id) { if (window.default_location_id) {
let location = this.locations.filter( let location = this.locations.filter(
(l) => l.id === window.default_location_id (l) => l.id === window.default_location_id
@ -102,7 +101,6 @@ export default {
}, },
makeConcernedPersonsLocation(locationType) { makeConcernedPersonsLocation(locationType) {
let locations = []; let locations = [];
console.log(this.suggestedEntities)
this.suggestedEntities.forEach( this.suggestedEntities.forEach(
(e) => { (e) => {
if (e.type === 'person' && e.current_household_address !== null){ if (e.type === 'person' && e.current_household_address !== null){
@ -111,7 +109,7 @@ export default {
onthefly: true, onthefly: true,
name: e.text, name: e.text,
address: { address: {
id: e.current_household_address.id, id: e.current_household_address.address_id,
}, },
locationType: locationType locationType: locationType
}); });
@ -129,7 +127,7 @@ export default {
type: 'location', type: 'location',
onthefly: true, onthefly: true,
name: e.text, name: e.text,
address: { id: e.address.id }, address: { id: e.address.address_id },
locationType: locationType locationType: locationType
}); });
} }
@ -138,7 +136,6 @@ export default {
return locations; return locations;
}, },
makeAccompanyingPeriodLocation(locationType) { makeAccompanyingPeriodLocation(locationType) {
console.log(this.activity)
const accPeriodLocation = this.activity.accompanyingPeriod.location; const accPeriodLocation = this.activity.accompanyingPeriod.location;
return { return {
type: 'location', type: 'location',
@ -147,7 +144,7 @@ export default {
address: { address: {
id: accPeriodLocation.address_id, id: accPeriodLocation.address_id,
text: `${accPeriodLocation.text} - ${accPeriodLocation.postcode.code} ${accPeriodLocation.postcode.name}` text: `${accPeriodLocation.text} - ${accPeriodLocation.postcode.code} ${accPeriodLocation.postcode.name}`
}, //TODO is the id sufficient? },
locationType: locationType locationType: locationType
} }
} }

View File

@ -28,7 +28,6 @@ const store = createStore({
}, },
getters: { getters: {
suggestedEntities(state) { suggestedEntities(state) {
console.log(state.activity);
if (typeof state.activity.accompanyingPeriod === "undefined") { if (typeof state.activity.accompanyingPeriod === "undefined") {
return []; return [];
} }
@ -304,14 +303,28 @@ const store = createStore({
let hiddenLocation = document.getElementById( let hiddenLocation = document.getElementById(
"chill_activitybundle_activity_location" "chill_activitybundle_activity_location"
); );
//TODO post the location if new location on-the-fly
if (value.onthefly) { if (value.onthefly) {
postLocation(value) const body = {
"type": "location",
"name": value.name === '__AccompanyingCourseLocation__' ? null : value.name,
"locationType": {
"id": value.locationType.id,
"type": "location-type"
}
};
if (value.address.id) {
Object.assign(body, {
"address": {
"id": value.address.id
},
})
}
postLocation(body)
.then( .then(
location => hiddenLocation.value = location.id location => hiddenLocation.value = location.id
).catch( ).catch(
err => { err => {
this.errors.push(err.message); console.log(err.message);
} }
); );
} else { } else {