patch Address to accompanyingPeriod: build payload for differents cases

use uniq patch api endpoint, build payload body in action,
call updateAddress action when submitting, assigning or removing.
This commit is contained in:
2021-08-16 16:23:10 +02:00
parent 966292cdd5
commit 107699ec31
4 changed files with 48 additions and 40 deletions

View File

@@ -48,32 +48,4 @@ const postAddressToHousehold = (householdId, addressId) => {
};
/*
* Endpoint AccompanyingPeriod
* method POST, post AccompanyingPeriod AddressLocation (temporary address)
*
* @id integer - id of AccompanyingPeriod
* @body Object - dictionary with changes to post
*/
const patchAddressToAccompanyingPeriod = (accompanyingPeriodId, addressId) => {
const body = {
'type': 'accompanying_period',
'id': accompanyingPeriodId,
'personLocation': null,
'addressLocation': {
'id': addressId
}
};
const url = `/api/1.0/person/accompanying-course/${accompanyingPeriodId}.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');
});
};
export { postAddressToPerson, postAddressToHousehold, patchAddressToAccompanyingPeriod };
export { postAddressToPerson, postAddressToHousehold };