refactor: clean payload
gitea/salix-front/pipeline/pr-master This commit is unstable
Details
gitea/salix-front/pipeline/pr-master This commit is unstable
Details
This commit is contained in:
parent
ae9cc49add
commit
a3b1095952
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue