add Comment component, make POST comment request

This commit is contained in:
2021-05-17 15:56:58 +02:00
parent 2aa13dceff
commit e0dc0a8fdb
6 changed files with 111 additions and 9 deletions

View File

@@ -121,18 +121,27 @@ const postResource = (id, payload, method) => {
/*
* Endpoint v.2 chill_api_single_accompanying_course_comment,
* method POST/DELETE, add/remove a comment to the accompanyingCourse
* method POST/DELETE/PATCH, add/remove a comment to the accompanyingCourse
*
* @id integer - id of accompanyingCourse
* @payload
* @method string - POST or DELETE
* @method string - POST, DELETE or PATCH
*/
const postComment = (id, payload, method) => {
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 = `/1.0/person/accompanying-course/${id}/comment.json`;
const url = `/api/1.0/person/accompanying-course/${id}/comment.json`;
return fetch(url, {
method: method,
method: payload.method,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
@@ -142,7 +151,7 @@ const postComment = (id, payload, method) => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
}
};
export {
getAccompanyingCourse,