mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-12-17 15:45:43 +00:00
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
import { getSocialIssues } from 'ChillPersonAssets/vuejs/AccompanyingCourse/api.js';
|
|
|
|
/*
|
|
* Load socialActions by socialIssue (id)
|
|
*/
|
|
const getSocialActionByIssue = (id) => {
|
|
const url = `/api/1.0/person/social/social-action/by-social-issue/${id}.json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* 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');
|
|
});
|
|
};
|
|
|
|
|
|
/*
|
|
* Load Location Types by defaultFor
|
|
* @param {string} entity - can be "person" or "thirdparty"
|
|
*/
|
|
const getLocationTypesByDefaultFor = (entity) => {
|
|
return getLocationTypes().then(response =>
|
|
response.results.filter(t => t.defaultFor === entity)[0]
|
|
);
|
|
};
|
|
|
|
/*
|
|
* Post a Location
|
|
*/
|
|
const postLocation = (body) => {
|
|
const url = `/api/1.0/main/location.json`;
|
|
return fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=utf-8'
|
|
},
|
|
body: JSON.stringify(body)
|
|
})
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
export {
|
|
getSocialIssues,
|
|
getSocialActionByIssue,
|
|
getLocations,
|
|
getLocationTypes,
|
|
getLocationTypesByDefaultFor,
|
|
postLocation
|
|
};
|