refactor: clean payload
gitea/salix-front/pipeline/pr-master This commit is unstable Details

This commit is contained in:
Jon Elias 2025-03-26 13:51:03 +01:00
parent ae9cc49add
commit a3b1095952
1 changed files with 16 additions and 8 deletions

View File

@ -93,20 +93,28 @@ const updateAddressTicket = async () => {
};
const updateObservations = async (payload) => {
if (isPayloadEmpty(payload)) return;
cleanPayload(payload);
await axios.post('AddressObservations/crud', payload);
notes.value = [];
deletes.value = [];
};
function isPayloadEmpty(payload) {
return ['creates', 'deletes', 'updates'].every(
(prop) =>
!payload[prop] ||
payload[prop].length === 0 ||
payload[prop].every((item) => item === undefined || item === null),
);
function cleanPayload(payload) {
['creates', 'deletes', 'updates'].forEach((prop) => {
if (prop === 'creates' || prop === 'updates') {
payload[prop] = payload[prop].filter(
(item) => item.description !== '' && item.observationTypeFk !== '',
);
}
if (prop === 'deletes') {
payload[prop] = payload[prop].filter(
(item) => item !== null && item !== undefined,
);
}
return payload[prop];
});
}
async function updateAll({ data, payload }) {
await updateObservations(payload);
await updateAddress(data);