fix initialComment with patch endpoint

This commit is contained in:
2021-05-19 10:34:17 +02:00
parent 9ef397e935
commit 27f49b2aa3
3 changed files with 30 additions and 54 deletions

View File

@@ -119,45 +119,10 @@ const postResource = (id, payload, method) => {
});
};
/*
* Endpoint v.2 chill_api_single_accompanying_course_comment,
* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse
*
* @id integer - id of accompanyingCourse
* @payload
* @method string - POST, DELETE or PATCH
*/
const postComment = (id, payload) => {
console.log('payload', payload);
const body = { type: "accompanying_period_comment" };
switch (payload.method) {
case 'POST':
body['content'] = payload.content;
break;
case 'DELETE':
body['id'] = 42;
break;
}
console.log('body', body);
const url = `/api/1.0/person/accompanying-course/${id}/comment.json`;
return fetch(url, {
method: payload.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,
postComment
};