WIP Добавил обновление дополнительной информации

This commit is contained in:
DwCay
2023-05-02 19:14:36 +03:00
parent 4b4fa45e9c
commit eb76007da1
5 changed files with 87 additions and 37 deletions

View File

@@ -63,6 +63,32 @@ export function getRequestArrayData(
return requests.concat(deleteRequests);
}
export function getRequestNote(note, initNote, personId) {
if (note.id) {
const initChangeNote = initNote?.value || {
id: initNote.id,
value: initNote.description,
};
if (note.value && note.value !== initChangeNote.value) {
return fetchWrapper.post(`general/note/${note.id}/update/`, {
title: note.value,
description: note.value,
});
}
if (!note.value) {
return fetchWrapper.del(`general/note/${note.id}/delete/`);
}
}
if (!note.id && note.value) {
return fetchWrapper.post(`general/note/create/`, {
title: note.value,
description: note.value,
person: personId,
});
}
return Promise.resolve();
}
export function getRequestConfidant(confidant, initConfidant, initPerson) {
const medicalId = localStorage.getItem("medicalId");
const fullName = `${confidant.last_name.value} ${confidant.first_name.value} ${confidant.patronymic.value}`;
@@ -82,29 +108,33 @@ export function getRequestConfidant(confidant, initConfidant, initPerson) {
return fetchWrapper
.post(`general/person/create/`, { full_name: fullName })
.then((res) => {
return Promise.allSettled(
getRequestArrayData(
[],
contacts,
"person",
res.id,
"general",
"contact"
return getRequestNote(confidant.note, null, res.id)
.then(() =>
Promise.allSettled(
getRequestArrayData(
[],
contacts,
"person",
res.id,
"general",
"contact"
)
)
)
).then(() =>
fetchWrapper.post(
`medical_card/medical_history/${medicalId}/update/`,
{
confidant: [
{
person: {
id: res.id,
.then(() =>
fetchWrapper.post(
`medical_card/medical_history/${medicalId}/update/`,
{
confidant: [
{
person: {
id: res.id,
},
},
},
],
}
)
);
],
}
)
);
});
} else {
if (initPerson) {
@@ -126,6 +156,9 @@ export function getRequestConfidant(confidant, initConfidant, initPerson) {
.post(`general/person/${confidant.id}/update/`, {
full_name: fullName,
})
.then(() =>
getRequestNote(confidant.note, initPerson.note, confidant.id)
)
.then(() => {
if (contacts.length) {
return Promise.allSettled(
@@ -159,6 +192,9 @@ export function getRequestConfidant(confidant, initConfidant, initPerson) {
.post(`general/person/${confidant.id}/update/`, {
full_name: fullName,
})
.then(() =>
getRequestNote(confidant.note, initConfidant.note, confidant.id)
)
.then(() => {
if (contacts.length) {
return Promise.allSettled(