add and remove requestor functions

This commit is contained in:
2021-05-10 18:46:21 +02:00
parent 4e31b3e424
commit f7c08f02c2
3 changed files with 83 additions and 19 deletions

View File

@@ -28,7 +28,36 @@ const postParticipation = (id, person_id, method) => {
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify({id: person_id})
body: JSON.stringify({person_id: person_id})
})
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
/*
* Endpoint v.2 chill_api_single_accompanying_course_requestor,
* method POST/DELETE, add/close a requestor to the accompanyingCourse
*
* @id integer - id of accompanyingCourse
* @payload object of type person|thirdparty
* @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);
const url = `/api/1.0/person/accompanying-course/${id}/requestor.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(); }
@@ -38,5 +67,6 @@ const postParticipation = (id, person_id, method) => {
export {
getAccompanyingCourse,
postParticipation
postParticipation,
postRequestor
};