Merge pull request 'HOTFIX: #6943 hotFix_AddressObservation_crud' (!945) from hotFix_AddressObservation_crud into master
gitea/salix-front/pipeline/head This commit looks good
Details
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #945 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
b8293d91e8
|
@ -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 = [];
|
||||
|
|
Loading…
Reference in New Issue