mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
location: use fetchResults for getLocations and getLocationTypes
This commit is contained in:
parent
f002d48efd
commit
5aa5cb3e08
@ -1,4 +1,5 @@
|
||||
import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api.js';
|
||||
import { fetchResults } from 'ChillMainAssets/lib/api/apiMethods';
|
||||
|
||||
/*
|
||||
* Load socialActions by socialIssue (id)
|
||||
@ -12,44 +13,20 @@ const getSocialActionByIssue = (id) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Load Locations
|
||||
*/
|
||||
const getLocations = () => {
|
||||
const url = `/api/1.0/main/location.json`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Load Location Types
|
||||
*/
|
||||
const getLocationTypes = () => {
|
||||
const url = `/api/1.0/main/location-type.json`;
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
const getLocations = () => fetchResults('/api/1.0/main/location.json');
|
||||
|
||||
const getLocationTypes = () => fetchResults('/api/1.0/main/location-type.json');
|
||||
|
||||
/*
|
||||
* Load Location Type by defaultFor
|
||||
* @param {string} entity - can be "person" or "thirdparty"
|
||||
*/
|
||||
const getLocationTypeByDefaultFor = (entity) => {
|
||||
return getLocationTypes().then(response =>
|
||||
response.results.filter(t => t.defaultFor === entity)[0]
|
||||
return getLocationTypes().then(results =>
|
||||
results.filter(t => t.defaultFor === entity)[0]
|
||||
);
|
||||
};
|
||||
|
||||
/*
|
||||
* Post a Location
|
||||
*/
|
||||
const postLocation = (body) => {
|
||||
const url = `/api/1.0/main/location.json`;
|
||||
return fetch(url, {
|
||||
|
@ -59,10 +59,9 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
getLocations().then(
|
||||
(response) =>
|
||||
new Promise((resolve) => {
|
||||
(results) => {
|
||||
getLocationTypeByDefaultFor('person').then(
|
||||
personLocationType => {
|
||||
(personLocationType) => {
|
||||
if (personLocationType) {
|
||||
const personLocation = this.makeAccompanyingPeriodLocation(personLocationType);
|
||||
const concernedPersonsLocation =
|
||||
@ -82,7 +81,7 @@ export default {
|
||||
},
|
||||
{
|
||||
locationGroup: 'Autres localisations',
|
||||
locations: response.results
|
||||
locations: results
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -101,11 +100,9 @@ export default {
|
||||
);
|
||||
this.$store.dispatch("updateLocation", location);
|
||||
}
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
})
|
||||
);
|
||||
},
|
||||
methods: {
|
||||
labelAccompanyingCourseLocation(value) {
|
||||
|
@ -214,10 +214,9 @@ export default {
|
||||
return cond;
|
||||
},
|
||||
getLocationTypesList() {
|
||||
getLocationTypes().then(response => new Promise(resolve => {
|
||||
this.locationTypes = response.results.filter(t => t.availableForUsers === true);
|
||||
resolve();
|
||||
}))
|
||||
getLocationTypes().then(results => {
|
||||
this.locationTypes = results.filter(t => t.availableForUsers === true);
|
||||
})
|
||||
},
|
||||
openModal() {
|
||||
this.modal.showModal = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user