From 064dbfc4324caf1d967acee6ebbffefef9e8043f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 15 Nov 2024 12:20:50 +0000 Subject: [PATCH] fix: #6943 Update AddressObservations --- .../components/CustomerAddressEdit.vue | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index 1e5387815..0ea8315d6 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -23,6 +23,7 @@ const incoterms = ref([]); const customsAgents = ref([]); const observationTypes = ref([]); const notes = ref([]); +let originalNotes = []; const deletes = ref([]); onBeforeMount(() => { @@ -42,7 +43,8 @@ const getData = async (observations) => { }); if (data.length) { - notes.value = data + originalNotes = data; + notes.value = originalNotes .map((observation) => { const type = observationTypes.value.find( (type) => type.id === observation.observationTypeFk @@ -81,14 +83,24 @@ const deleteNote = (id, index) => { }; const onDataSaved = async () => { - let payload = {}; - const creates = notes.value.filter((note) => note.$isNew); - if (creates.length) { - payload.creates = creates; - } - if (deletes.value.length) { - payload.deletes = deletes.value; - } + let payload = { + creates: notes.value.filter((note) => note.$isNew), + deletes: deletes.value, + updates: notes.value + .filter((note) => + originalNotes.some( + (oNote) => + oNote.id === note.id && + (note.description !== oNote.description || + note.observationTypeFk !== oNote.observationTypeFk) + ) + ) + .map((note) => ({ + data: note, + where: { id: note.id }, + })), + }; + await axios.post('AddressObservations/crud', payload); notes.value = []; deletes.value = [];