interlocutors: actions, mutations, fetch request (wip)

This commit is contained in:
2021-05-12 17:40:23 +02:00
parent 6da8f1c107
commit eac42581a6
3 changed files with 81 additions and 17 deletions

View File

@@ -1,3 +1,14 @@
const getBodyTypeId = (payload) => {
const body = {};
if (payload !== null) {
const typeId = `${payload.result.type}_id`;
body[typeId] = payload.result[typeId];
};
console.log('body', body);
return body;
}
/*
* Endpoint v.2 chill_api_single_accompanying_course__entity
* method GET/HEAD, get AccompanyingCourse Instance
@@ -68,12 +79,7 @@ const postParticipation = (id, person_id, method) => {
* @method string - POST or DELETE
*/
const postRequestor = (id, payload, method) => {
const body = {};
if (payload !== null) {
const typeId = `${payload.result.type}_id`;
body[typeId] = payload.result[typeId];
};
console.log('body', body);
const body = getBodyTypeId(payload);
const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`;
return fetch(url, {
method: method,
@@ -88,9 +94,34 @@ const postRequestor = (id, payload, method) => {
});
};
/*
* Endpoint v.2 chill_api_single_accompanying_course_resource,
* method POST/DELETE, add/remove a resource to the accompanyingCourse
*
* @id integer - id of accompanyingCourse
* @payload object of type person|thirdparty
* @method string - POST or DELETE
*/
const postResource = (id, payload, method) => {
const body = getBodyTypeId(payload);
const url = `/api/1.0/person/accompanying-course/${id}/resource.json`;
return fetch(url, {
method: method,
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 {
getAccompanyingCourse,
patchAccompanyingCourse,
postParticipation,
postRequestor
postRequestor,
postResource
};