diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js index 93a4f8f7a..2c9b7c999 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js @@ -1,3 +1,14 @@ + +const getBodyTypeId = (payload) => { + const body = {}; + if (payload !== null) { + const typeId = `${payload.result.type}_id`; + body[typeId] = payload.result[typeId]; + }; + console.log('body', body); + return body; +} + /* * Endpoint v.2 chill_api_single_accompanying_course__entity * method GET/HEAD, get AccompanyingCourse Instance @@ -68,12 +79,7 @@ const postParticipation = (id, person_id, method) => { * @method string - POST or DELETE */ const postRequestor = (id, payload, method) => { - const body = {}; - if (payload !== null) { - const typeId = `${payload.result.type}_id`; - body[typeId] = payload.result[typeId]; - }; - console.log('body', body); + const body = getBodyTypeId(payload); const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`; return fetch(url, { method: method, @@ -88,9 +94,34 @@ const postRequestor = (id, payload, method) => { }); }; +/* +* Endpoint v.2 chill_api_single_accompanying_course_resource, +* method POST/DELETE, add/remove a resource to the accompanyingCourse +* +* @id integer - id of accompanyingCourse +* @payload object of type person|thirdparty +* @method string - POST or DELETE +*/ +const postResource = (id, payload, method) => { + const body = getBodyTypeId(payload); + const url = `/api/1.0/person/accompanying-course/${id}/resource.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 + postRequestor, + postResource }; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Interlocutors.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Interlocutors.vue index 0d2f0ccaf..eced890d9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Interlocutors.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Interlocutors.vue @@ -37,8 +37,8 @@