WIP Добавил обновление данных доверенных лиц
This commit is contained in:
@@ -62,3 +62,130 @@ export function getRequestArrayData(
|
||||
});
|
||||
return requests.concat(deleteRequests);
|
||||
}
|
||||
|
||||
export function getRequestConfidant(confidant, initConfidant, initPerson) {
|
||||
const medicalId = localStorage.getItem("medicalId");
|
||||
const fullName = `${confidant.last_name.value} ${confidant.first_name.value} ${confidant.patronymic.value}`;
|
||||
let contacts = [];
|
||||
const phone = confidant.phone.value
|
||||
? { username: confidant.phone.value, kind: "PHONE" }
|
||||
: null;
|
||||
const email = confidant.email.value
|
||||
? { username: confidant.email.value, kind: "EMAIL" }
|
||||
: null;
|
||||
if (confidant.phone.id) phone.id = confidant.phone.id;
|
||||
if (confidant.email.id) email.id = confidant.email.id;
|
||||
if (phone) contacts.push(phone);
|
||||
if (email) contacts.push(email);
|
||||
contacts = contacts.concat(confidant.networks);
|
||||
if (!confidant.id) {
|
||||
return fetchWrapper
|
||||
.post(`general/person/create/`, { full_name: fullName })
|
||||
.then((res) => {
|
||||
return Promise.allSettled(
|
||||
getRequestArrayData(
|
||||
[],
|
||||
contacts,
|
||||
"person",
|
||||
res.id,
|
||||
"general",
|
||||
"contact"
|
||||
)
|
||||
).then(() =>
|
||||
fetchWrapper.post(
|
||||
`medical_card/medical_history/${medicalId}/update/`,
|
||||
{
|
||||
confidant: [
|
||||
{
|
||||
person: {
|
||||
id: res.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
if (initPerson) {
|
||||
if (initConfidant && initPerson.id !== initConfidant.id) {
|
||||
fetchWrapper.del(
|
||||
`medical_card/medical_history/${medicalId}/delete_confidant/`,
|
||||
{
|
||||
confidants: [
|
||||
{
|
||||
person: {
|
||||
id: initConfidant.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
}
|
||||
return fetchWrapper
|
||||
.post(`general/person/${confidant.id}/update/`, {
|
||||
full_name: fullName,
|
||||
})
|
||||
.then(() => {
|
||||
if (contacts.length) {
|
||||
return Promise.allSettled(
|
||||
getRequestArrayData(
|
||||
initPerson.contacts,
|
||||
contacts,
|
||||
"person",
|
||||
confidant.id,
|
||||
"general",
|
||||
"contact"
|
||||
)
|
||||
).then(() =>
|
||||
fetchWrapper.post(
|
||||
`medical_card/medical_history/${medicalId}/update/`,
|
||||
{
|
||||
confidant: [
|
||||
{
|
||||
person: {
|
||||
id: confidant.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (initConfidant && !initPerson) {
|
||||
return fetchWrapper
|
||||
.post(`general/person/${confidant.id}/update/`, {
|
||||
full_name: fullName,
|
||||
})
|
||||
.then(() => {
|
||||
if (contacts.length) {
|
||||
return Promise.allSettled(
|
||||
getRequestArrayData(
|
||||
initConfidant.networks,
|
||||
contacts,
|
||||
"person",
|
||||
confidant.id,
|
||||
"general",
|
||||
"contact"
|
||||
)
|
||||
).then(() =>
|
||||
fetchWrapper.post(
|
||||
`medical_card/medical_history/${medicalId}/update/`,
|
||||
{
|
||||
confidant: [
|
||||
{
|
||||
person: {
|
||||
id: confidant.id,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user