location: fix error when there is no defaultFor defined for locationType entities

This commit is contained in:
nobohan 2021-11-25 16:53:02 +01:00
parent aad4b6e5d0
commit f002d48efd

View File

@ -63,6 +63,7 @@ export default {
new Promise((resolve) => { new Promise((resolve) => {
getLocationTypeByDefaultFor('person').then( getLocationTypeByDefaultFor('person').then(
personLocationType => { personLocationType => {
if (personLocationType) {
const personLocation = this.makeAccompanyingPeriodLocation(personLocationType); const personLocation = this.makeAccompanyingPeriodLocation(personLocationType);
const concernedPersonsLocation = const concernedPersonsLocation =
this.makeConcernedPersonsLocation(personLocationType); this.makeConcernedPersonsLocation(personLocationType);
@ -77,12 +78,23 @@ export default {
}, },
{ {
locationGroup: 'Parties concernées', locationGroup: 'Parties concernées',
locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]}, locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]
},
{ {
locationGroup: 'Autres localisations', locationGroup: 'Autres localisations',
locations: response.results locations: response.results
} }
]; ];
}
)
} else {
this.locations = [
{
locationGroup: 'Localisations',
locations: response.results
}
];
}
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
@ -92,8 +104,6 @@ export default {
resolve(); resolve();
} }
) )
}
)
}) })
); );
}, },
@ -102,11 +112,13 @@ export default {
return `${value.address.text} (${value.locationType.title.fr})` return `${value.address.text} (${value.locationType.title.fr})`
}, },
customLabel(value) { customLabel(value) {
return value.name ? return value.locationType
value.name === '__AccompanyingCourseLocation__' ? ? value.name
this.labelAccompanyingCourseLocation(value) : ? value.name === '__AccompanyingCourseLocation__'
`${value.name} (${value.locationType.title.fr})` : ? this.labelAccompanyingCourseLocation(value)
value.locationType.title.fr; : `${value.name} (${value.locationType.title.fr})`
: value.locationType.title.fr
: '';
}, },
makeConcernedPersonsLocation(locationType) { makeConcernedPersonsLocation(locationType) {
let locations = []; let locations = [];