diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js index 8e49a2e21..34eee3f8f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js @@ -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 };