From 4a04628d5bc25cc51791cadaf30142403f795ada Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 12 May 2021 18:50:18 +0200 Subject: [PATCH] adapt payload body to entity convention with type + id --- .../public/vuejs/AccompanyingCourse/api.js | 11 ++++++----- .../public/vuejs/AccompanyingCourse/store/index.js | 14 +++++++------- .../public/vuejs/_components/AddPersons.vue | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js index 2c9b7c999..2c136ac16 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/api.js @@ -2,8 +2,8 @@ const getBodyTypeId = (payload) => { const body = {}; if (payload !== null) { - const typeId = `${payload.result.type}_id`; - body[typeId] = payload.result[typeId]; + body['type'] = payload.type; + body['id'] = payload.id; }; console.log('body', body); return body; @@ -52,17 +52,18 @@ const patchAccompanyingCourse = (id, body) => { * method POST/DELETE, add/close a participation to the accompanyingCourse * * @id integer - id of accompanyingCourse -* @person_id integer - id of person +* @payload integer - id of person * @method string - POST or DELETE */ -const postParticipation = (id, person_id, method) => { +const postParticipation = (id, payload, method) => { + const body = getBodyTypeId(payload); const url = `/api/1.0/person/accompanying-course/${id}/participation.json`; return fetch(url, { method: method, headers: { 'Content-Type': 'application/json;charset=utf-8' }, - body: JSON.stringify({person_id: person_id}) + body: JSON.stringify(body) }) .then(response => { if (response.ok) { return response.json(); } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index d003ed98c..2d97baca2 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -66,7 +66,7 @@ let initPromise = getAccompanyingCourse(id) }, closeParticipation({ commit }, payload) { console.log('## action: fetch delete participation: payload', payload); - postParticipation(id, payload.person.person_id, 'DELETE') + postParticipation(id, payload.person, 'DELETE') .then(participation => new Promise((resolve, reject) => { commit('closeParticipation', { participation, payload }); resolve(); @@ -77,7 +77,7 @@ let initPromise = getAccompanyingCourse(id) }, addParticipation({ commit }, payload) { console.log('## action: fetch post participation (select item): payload', payload); - postParticipation(id, payload.result.person_id, 'POST') + postParticipation(id, payload.result, 'POST') .then(participation => new Promise((resolve, reject) => { commit('addParticipation', participation); resolve(); @@ -86,12 +86,12 @@ let initPromise = getAccompanyingCourse(id) state.errorMsg.push(error.message); }); }, - removeRequestor({ commit }) { + removeRequestor({ commit, dispatch }) { console.log('## action: fetch delete requestor'); postRequestor(id, null, 'DELETE') .then(requestor => new Promise((resolve, reject) => { commit('removeRequestor'); - commit('requestorIsAnonymous', false); + dispatch('requestorIsAnonymous', false); resolve(); })) .catch((error) => { @@ -100,7 +100,7 @@ let initPromise = getAccompanyingCourse(id) }, addRequestor({ commit }, payload) { console.log('## action: fetch post requestor: payload', payload); - postRequestor(id, payload, 'POST') + postRequestor(id, payload.result, 'POST') .then(requestor => new Promise((resolve, reject) => { commit('addRequestor', requestor); resolve(); @@ -111,7 +111,7 @@ let initPromise = getAccompanyingCourse(id) }, requestorIsAnonymous({ commit }, payload) { console.log('## action: fetch patch AccompanyingCourse: payload', payload); - patchAccompanyingCourse(id, { requestorAnonymous: payload }) + patchAccompanyingCourse(id, { type: "accompanying_period", requestorAnonymous: payload }) .then(course => new Promise((resolve, reject) => { commit('requestorIsAnonymous', course.requestorAnonymous) resolve(); @@ -133,7 +133,7 @@ let initPromise = getAccompanyingCourse(id) }, addInterlocutor({ commit }, payload) { console.log('## action: fetch postInterlocutor: payload', payload); - postResource(id, payload, 'POST') + postResource(id, payload.result, 'POST') .then(resource => new Promise((resolve, reject) => { commit('addInterlocutor', resource) resolve(); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 8e653466c..8698ed420 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -166,6 +166,7 @@ export default { if (query.length >= 3) { searchPersons_2({ query, options: this.options }) .then(suggested => new Promise((resolve, reject) => { + console.log('suggested', suggested); this.loadSuggestions(suggested.results); resolve(); })); @@ -174,6 +175,7 @@ export default { } }, loadSuggestions(suggested) { + console.log('suggested', suggested); this.search.suggested = suggested; this.search.suggested.forEach(function(item) { item.key = this.itemKey(item); @@ -200,8 +202,7 @@ export default { }, this); }, itemKey(item) { - let type = item.result.type; - return type + item.result[type + '_id']; + return item.result.type + item.result.id; } }, }