mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
adapt payload body to entity convention with type + id
This commit is contained in:
parent
0af78f814c
commit
4a04628d5b
@ -2,8 +2,8 @@
|
|||||||
const getBodyTypeId = (payload) => {
|
const getBodyTypeId = (payload) => {
|
||||||
const body = {};
|
const body = {};
|
||||||
if (payload !== null) {
|
if (payload !== null) {
|
||||||
const typeId = `${payload.result.type}_id`;
|
body['type'] = payload.type;
|
||||||
body[typeId] = payload.result[typeId];
|
body['id'] = payload.id;
|
||||||
};
|
};
|
||||||
console.log('body', body);
|
console.log('body', body);
|
||||||
return body;
|
return body;
|
||||||
@ -52,17 +52,18 @@ const patchAccompanyingCourse = (id, body) => {
|
|||||||
* method POST/DELETE, add/close a participation to the accompanyingCourse
|
* method POST/DELETE, add/close a participation to the accompanyingCourse
|
||||||
*
|
*
|
||||||
* @id integer - id of accompanyingCourse
|
* @id integer - id of accompanyingCourse
|
||||||
* @person_id integer - id of person
|
* @payload integer - id of person
|
||||||
* @method string - POST or DELETE
|
* @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`;
|
const url = `/api/1.0/person/accompanying-course/${id}/participation.json`;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: method,
|
method: method,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json;charset=utf-8'
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({person_id: person_id})
|
body: JSON.stringify(body)
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
|
@ -66,7 +66,7 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
closeParticipation({ commit }, payload) {
|
closeParticipation({ commit }, payload) {
|
||||||
console.log('## action: fetch delete participation: payload', 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) => {
|
.then(participation => new Promise((resolve, reject) => {
|
||||||
commit('closeParticipation', { participation, payload });
|
commit('closeParticipation', { participation, payload });
|
||||||
resolve();
|
resolve();
|
||||||
@ -77,7 +77,7 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
addParticipation({ commit }, payload) {
|
addParticipation({ commit }, payload) {
|
||||||
console.log('## action: fetch post participation (select item): payload', 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) => {
|
.then(participation => new Promise((resolve, reject) => {
|
||||||
commit('addParticipation', participation);
|
commit('addParticipation', participation);
|
||||||
resolve();
|
resolve();
|
||||||
@ -86,12 +86,12 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
state.errorMsg.push(error.message);
|
state.errorMsg.push(error.message);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeRequestor({ commit }) {
|
removeRequestor({ commit, dispatch }) {
|
||||||
console.log('## action: fetch delete requestor');
|
console.log('## action: fetch delete requestor');
|
||||||
postRequestor(id, null, 'DELETE')
|
postRequestor(id, null, 'DELETE')
|
||||||
.then(requestor => new Promise((resolve, reject) => {
|
.then(requestor => new Promise((resolve, reject) => {
|
||||||
commit('removeRequestor');
|
commit('removeRequestor');
|
||||||
commit('requestorIsAnonymous', false);
|
dispatch('requestorIsAnonymous', false);
|
||||||
resolve();
|
resolve();
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -100,7 +100,7 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
addRequestor({ commit }, payload) {
|
addRequestor({ commit }, payload) {
|
||||||
console.log('## action: fetch post requestor: payload', payload);
|
console.log('## action: fetch post requestor: payload', payload);
|
||||||
postRequestor(id, payload, 'POST')
|
postRequestor(id, payload.result, 'POST')
|
||||||
.then(requestor => new Promise((resolve, reject) => {
|
.then(requestor => new Promise((resolve, reject) => {
|
||||||
commit('addRequestor', requestor);
|
commit('addRequestor', requestor);
|
||||||
resolve();
|
resolve();
|
||||||
@ -111,7 +111,7 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
requestorIsAnonymous({ commit }, payload) {
|
requestorIsAnonymous({ commit }, payload) {
|
||||||
console.log('## action: fetch patch AccompanyingCourse: payload', 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) => {
|
.then(course => new Promise((resolve, reject) => {
|
||||||
commit('requestorIsAnonymous', course.requestorAnonymous)
|
commit('requestorIsAnonymous', course.requestorAnonymous)
|
||||||
resolve();
|
resolve();
|
||||||
@ -133,7 +133,7 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
addInterlocutor({ commit }, payload) {
|
addInterlocutor({ commit }, payload) {
|
||||||
console.log('## action: fetch postInterlocutor: payload', payload);
|
console.log('## action: fetch postInterlocutor: payload', payload);
|
||||||
postResource(id, payload, 'POST')
|
postResource(id, payload.result, 'POST')
|
||||||
.then(resource => new Promise((resolve, reject) => {
|
.then(resource => new Promise((resolve, reject) => {
|
||||||
commit('addInterlocutor', resource)
|
commit('addInterlocutor', resource)
|
||||||
resolve();
|
resolve();
|
||||||
|
@ -166,6 +166,7 @@ export default {
|
|||||||
if (query.length >= 3) {
|
if (query.length >= 3) {
|
||||||
searchPersons_2({ query, options: this.options })
|
searchPersons_2({ query, options: this.options })
|
||||||
.then(suggested => new Promise((resolve, reject) => {
|
.then(suggested => new Promise((resolve, reject) => {
|
||||||
|
console.log('suggested', suggested);
|
||||||
this.loadSuggestions(suggested.results);
|
this.loadSuggestions(suggested.results);
|
||||||
resolve();
|
resolve();
|
||||||
}));
|
}));
|
||||||
@ -174,6 +175,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadSuggestions(suggested) {
|
loadSuggestions(suggested) {
|
||||||
|
console.log('suggested', suggested);
|
||||||
this.search.suggested = suggested;
|
this.search.suggested = suggested;
|
||||||
this.search.suggested.forEach(function(item) {
|
this.search.suggested.forEach(function(item) {
|
||||||
item.key = this.itemKey(item);
|
item.key = this.itemKey(item);
|
||||||
@ -200,8 +202,7 @@ export default {
|
|||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
itemKey(item) {
|
itemKey(item) {
|
||||||
let type = item.result.type;
|
return item.result.type + item.result.id;
|
||||||
return type + item.result[type + '_id'];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user