WIP Добавил обновление Контактов

This commit is contained in:
DwCay
2023-04-19 18:11:05 +03:00
parent 5baefcc1f8
commit a2898f4b4f
6 changed files with 120 additions and 50 deletions

View File

@@ -239,46 +239,6 @@ const actions = {
localStorage.removeItem("medicalId");
});
},
updateContactsData({ commit, state }) {
const personId = state.medicalCard.person.id;
const initContacts = state.medicalCard.person.contacts;
const allNewContacts = [
...state.contactsData.phones,
...state.contactsData.emails,
...state.contactsData.networks,
];
let requestDelete = initContacts
.filter((el) => !allNewContacts.find((newNet) => newNet.id === el.id))
.map((el) => fetchWrapper.del(`general/contact/${el.id}/delete/`));
const request = allNewContacts
.map((contact) => {
let initNetwork = initContacts.find((el) => el.id === contact.id);
if (!contact.id && contact.username && contact.kind) {
return fetchWrapper.post(`general/contact/create/`, {
person: personId,
username: contact.username,
kind: contact.kind,
});
}
if (
contact.id &&
contact.username &&
contact.username !== initNetwork.username
) {
return fetchWrapper.post(`general/contact/${contact.id}/update/`, {
person: personId,
username: contact.username,
kind: contact.kind,
});
}
return Promise.resolve();
})
.concat(requestDelete);
return Promise.allSettled(request).then(() =>
actions.getMedicalCardData({ commit })
);
},
};
const mutations = {