forked from verdnatura/salix-front
Merge pull request 'HOTFIX: #6943 hotFix_AddressObservation_crud' (!945) from hotFix_AddressObservation_crud into master
Reviewed-on: verdnatura/salix-front#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 customsAgents = ref([]);
|
||||||
const observationTypes = ref([]);
|
const observationTypes = ref([]);
|
||||||
const notes = ref([]);
|
const notes = ref([]);
|
||||||
|
let originalNotes = [];
|
||||||
const deletes = ref([]);
|
const deletes = ref([]);
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
|
@ -42,7 +43,8 @@ const getData = async (observations) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.length) {
|
if (data.length) {
|
||||||
notes.value = data
|
originalNotes = data;
|
||||||
|
notes.value = originalNotes
|
||||||
.map((observation) => {
|
.map((observation) => {
|
||||||
const type = observationTypes.value.find(
|
const type = observationTypes.value.find(
|
||||||
(type) => type.id === observation.observationTypeFk
|
(type) => type.id === observation.observationTypeFk
|
||||||
|
@ -81,14 +83,24 @@ const deleteNote = (id, index) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDataSaved = async () => {
|
const onDataSaved = async () => {
|
||||||
let payload = {};
|
let payload = {
|
||||||
const creates = notes.value.filter((note) => note.$isNew);
|
creates: notes.value.filter((note) => note.$isNew),
|
||||||
if (creates.length) {
|
deletes: deletes.value,
|
||||||
payload.creates = creates;
|
updates: notes.value
|
||||||
}
|
.filter((note) =>
|
||||||
if (deletes.value.length) {
|
originalNotes.some(
|
||||||
payload.deletes = deletes.value;
|
(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);
|
await axios.post('AddressObservations/crud', payload);
|
||||||
notes.value = [];
|
notes.value = [];
|
||||||
deletes.value = [];
|
deletes.value = [];
|
||||||
|
|
Loading…
Reference in New Issue