From dae5fb5241c8835049544e22d11404a5dbaf02e4 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 17 Apr 2025 20:39:04 +0200 Subject: [PATCH] refactor: refs #8217 eliminate unnecessary onBeforeSave function --- src/filters/getDifferences.js | 30 +++++++++++------ src/pages/Claim/Card/ClaimBasicData.vue | 8 ----- src/pages/Customer/Card/CustomerBasicData.vue | 32 +------------------ .../Customer/Card/CustomerFiscalData.vue | 8 ----- 4 files changed, 21 insertions(+), 57 deletions(-) diff --git a/src/filters/getDifferences.js b/src/filters/getDifferences.js index 5a1c42b97..13ed784c5 100644 --- a/src/filters/getDifferences.js +++ b/src/filters/getDifferences.js @@ -1,16 +1,26 @@ export default function getDifferences(initialData, formData) { - const differences = {}; - if (initialData) delete initialData.$index; - if (formData) delete formData.$index; + const diff = {}; + if (!initialData) return diff; + if (!formData) return initialData; + delete initialData.$index; + delete formData.$index; + + for (const key in initialData) { + if ( + formData[key] && + JSON.stringify(initialData[key]) !== JSON.stringify(formData[key]) + ) { + diff[key] = formData[key]; + } + } for (const key in formData) { - if (formData.hasOwnProperty(key)) { - if (!initialData.hasOwnProperty(key) || formData[key] !== initialData[key]) { - if (initialData) { - differences[key] = formData[key]; - } - } + if ( + initialData[key] === undefined || + JSON.stringify(initialData[key]) !== JSON.stringify(formData[key]) + ) { + diff[key] = formData[key]; } } - return differences; + return diff; } diff --git a/src/pages/Claim/Card/ClaimBasicData.vue b/src/pages/Claim/Card/ClaimBasicData.vue index 7e7d42ae8..0632370d6 100644 --- a/src/pages/Claim/Card/ClaimBasicData.vue +++ b/src/pages/Claim/Card/ClaimBasicData.vue @@ -15,13 +15,6 @@ import VnAvatar from 'src/components/ui/VnAvatar.vue'; const route = useRoute(); const { t } = useI18n(); const workersOptions = ref([]); - -function onBeforeSave(formData, originalData) { - return getUpdatedValues( - Object.keys(getDifferences(formData, originalData)), - formData, - ); -}