adapt payload body to entity convention with type + id

This commit is contained in:
2021-05-12 18:50:18 +02:00
parent 0af78f814c
commit 4a04628d5b
3 changed files with 16 additions and 14 deletions

View File

@@ -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(); }