mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
208 lines
6.1 KiB
JavaScript
208 lines
6.1 KiB
JavaScript
/*
|
|
* Endpoint v.2 chill_api_single_accompanying_course__entity
|
|
* method GET/HEAD, get AccompanyingCourse Instance
|
|
*
|
|
* @id integer - id of accompanyingCourse
|
|
*/
|
|
const getAccompanyingCourse = (id) => {
|
|
const url = `/api/1.0/person/accompanying-course/${id}.json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint v.2 chill_api_single_accompanying_course__entity
|
|
* method PATCH, patch AccompanyingCourse Instance
|
|
*
|
|
* @id integer - id of accompanyingCourse
|
|
* @body Object - dictionary with changes to post
|
|
*/
|
|
const patchAccompanyingCourse = (id, body) => {
|
|
console.log('body', body);
|
|
const url = `/api/1.0/person/accompanying-course/${id}.json`;
|
|
return fetch(url, {
|
|
method: 'PATCH',
|
|
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');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint to change 'DRAFT' step to 'CONFIRMED'
|
|
*/
|
|
const confirmAccompanyingCourse = (id) => {
|
|
const url = `/api/1.0/person/accompanying-course/${id}/confirm.json`
|
|
return fetch(url, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json;charset=utf-8'}
|
|
})
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint
|
|
*/
|
|
const getSocialIssues = () => {
|
|
const url = `/api/1.0/person/social-work/social-issue.json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint v.2 chill_api_single_accompanying_course_participation,
|
|
* method POST/DELETE, add/close a participation to the accompanyingCourse
|
|
*
|
|
* @id integer - id of accompanyingCourse
|
|
* @payload integer - id of person
|
|
* @method string - POST or DELETE
|
|
*/
|
|
const postParticipation = (id, payload, method) => {
|
|
const body = { type: payload.type, id: payload.id };
|
|
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(body)
|
|
})
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint v.2 chill_api_single_accompanying_course_requestor,
|
|
* method POST/DELETE, add/close a requestor to the accompanyingCourse
|
|
*
|
|
* @id integer - id of accompanyingCourse
|
|
* @payload object of type person|thirdparty
|
|
* @method string - POST or DELETE
|
|
*/
|
|
const postRequestor = (id, payload, method) => {
|
|
//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,
|
|
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');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* 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) => {
|
|
//console.log('payload', payload);
|
|
const body = { type: "accompanying_period_resource" };
|
|
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`;
|
|
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');
|
|
});
|
|
};
|
|
|
|
/*
|
|
* Endpoint to Add/remove SocialIssue
|
|
*/
|
|
const postSocialIssue = (id, body, method) => {
|
|
//console.log('api body and method', body, method);
|
|
const url = `/api/1.0/person/accompanying-course/${id}/socialissue.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');
|
|
});
|
|
};
|
|
|
|
const getUsers = () => {
|
|
const url = `/api/1.0/...json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
};
|
|
|
|
const getListOrigins = () => {
|
|
const url = `/api/1.0/person/accompanying-period/origin.json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
}
|
|
|
|
const getOrigin = (id) => {
|
|
const url = `/api/1.0/person/accompanying-period/origin/${id}.json`;
|
|
return fetch(url)
|
|
.then(response => {
|
|
if (response.ok) { return response.json(); }
|
|
throw Error('Error with request resource response');
|
|
});
|
|
}
|
|
|
|
export {
|
|
getAccompanyingCourse,
|
|
patchAccompanyingCourse,
|
|
confirmAccompanyingCourse,
|
|
getSocialIssues,
|
|
postParticipation,
|
|
postRequestor,
|
|
postResource,
|
|
getUsers,
|
|
getListOrigins,
|
|
getOrigin,
|
|
postSocialIssue
|
|
};
|