mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
prepare postComment fetch request
This commit is contained in:
parent
38f5854c6d
commit
55264da092
@ -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
|
* Endpoint v.2 chill_api_single_accompanying_course__entity
|
||||||
* method GET/HEAD, get AccompanyingCourse Instance
|
* method GET/HEAD, get AccompanyingCourse Instance
|
||||||
@ -56,7 +45,7 @@ const patchAccompanyingCourse = (id, body) => {
|
|||||||
* @method string - POST or DELETE
|
* @method string - POST or DELETE
|
||||||
*/
|
*/
|
||||||
const postParticipation = (id, payload, method) => {
|
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`;
|
const url = `/api/1.0/person/accompanying-course/${id}/participation.json`;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
@ -80,7 +69,9 @@ const postParticipation = (id, payload, method) => {
|
|||||||
* @method string - POST or DELETE
|
* @method string - POST or DELETE
|
||||||
*/
|
*/
|
||||||
const postRequestor = (id, payload, method) => {
|
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`;
|
const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
@ -104,12 +95,14 @@ const postRequestor = (id, payload, method) => {
|
|||||||
* @method string - POST or DELETE
|
* @method string - POST or DELETE
|
||||||
*/
|
*/
|
||||||
const postResource = (id, payload, method) => {
|
const postResource = (id, payload, method) => {
|
||||||
console.log('payload', payload);
|
//console.log('payload', payload);
|
||||||
const body = { type: "accompanying_period_resource" };
|
const body = { type: "accompanying_period_resource" };
|
||||||
if (method === 'DELETE') {
|
switch (method) {
|
||||||
body['id'] = payload.id;
|
case 'DELETE':
|
||||||
} else {
|
body['id'] = payload.id;
|
||||||
body['resource'] = getEntityTypeId(payload);
|
break;
|
||||||
|
default:
|
||||||
|
body['resource'] = { type: payload.type, id: payload.id };
|
||||||
}
|
}
|
||||||
console.log('body', body);
|
console.log('body', body);
|
||||||
const url = `/api/1.0/person/accompanying-course/${id}/resource.json`;
|
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 {
|
export {
|
||||||
getAccompanyingCourse,
|
getAccompanyingCourse,
|
||||||
patchAccompanyingCourse,
|
patchAccompanyingCourse,
|
||||||
postParticipation,
|
postParticipation,
|
||||||
postRequestor,
|
postRequestor,
|
||||||
postResource
|
postResource,
|
||||||
|
postComment
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user