prepare postComment fetch request

This commit is contained in:
Mathieu Jaumotte 2021-05-17 12:05:46 +02:00
parent 38f5854c6d
commit 55264da092

View File

@ -1,14 +1,3 @@
const getEntityTypeId = (payload) => {
const body = {};
if (payload !== null) {
body['type'] = payload.type;
body['id'] = payload.id;
};
console.log('body', body);
return body;
}
/*
* Endpoint v.2 chill_api_single_accompanying_course__entity
* method GET/HEAD, get AccompanyingCourse Instance
@ -56,7 +45,7 @@ const patchAccompanyingCourse = (id, body) => {
* @method string - POST or DELETE
*/
const postParticipation = (id, payload, method) => {
const body = getEntityTypeId(payload);
const body = { type: payload.type, id: payload.id };
const url = `/api/1.0/person/accompanying-course/${id}/participation.json`;
return fetch(url, {
method: method,
@ -80,7 +69,9 @@ const postParticipation = (id, payload, method) => {
* @method string - POST or DELETE
*/
const postRequestor = (id, payload, method) => {
const body = getEntityTypeId(payload);
//console.log('payload', payload);
const body = (payload)? { type: payload.type, id: payload.id } : {};
console.log('body', body);
const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`;
return fetch(url, {
method: method,
@ -104,12 +95,14 @@ const postRequestor = (id, payload, method) => {
* @method string - POST or DELETE
*/
const postResource = (id, payload, method) => {
console.log('payload', payload);
//console.log('payload', payload);
const body = { type: "accompanying_period_resource" };
if (method === 'DELETE') {
body['id'] = payload.id;
} else {
body['resource'] = getEntityTypeId(payload);
switch (method) {
case 'DELETE':
body['id'] = payload.id;
break;
default:
body['resource'] = { type: payload.type, id: payload.id };
}
console.log('body', body);
const url = `/api/1.0/person/accompanying-course/${id}/resource.json`;
@ -126,10 +119,36 @@ const postResource = (id, payload, method) => {
});
};
/*
* Endpoint v.2 chill_api_single_accompanying_course_comment,
* method POST/DELETE, add/remove a comment to the accompanyingCourse
*
* @id integer - id of accompanyingCourse
* @payload
* @method string - POST or DELETE
*/
const postComment = (id, payload, method) => {
console.log('payload', payload);
console.log('body', body);
const url = `/1.0/person/accompanying-course/${id}/comment.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,
postResource
postResource,
postComment
};