From 200a6714bb019781ddd1577c6c9f8e847263d802 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 15 Jul 2024 12:02:00 +0200 Subject: [PATCH 1/9] fix: refs #7722 delete sms --- db/routines/vn/procedures/clean.sql | 4 ++++ db/versions/11152-goldenRaphis/00-firstScript.sql | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 db/versions/11152-goldenRaphis/00-firstScript.sql diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 6645b9cb2..613139fc7 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -28,6 +28,10 @@ BEGIN DELETE FROM ticketDown WHERE created < util.yesterday(); DELETE FROM entryLog WHERE creationDate < v2Months; DELETE IGNORE FROM expedition WHERE created < v26Months; + DELETE cs.* + FROM sms s + JOIN clientSms cs ON cs.smsFk = s.id + WHERE s. created < v18Months; DELETE FROM sms WHERE created < v18Months; DELETE FROM saleTracking WHERE created < v1Years; DELETE FROM productionError WHERE dated < v1Years; diff --git a/db/versions/11152-goldenRaphis/00-firstScript.sql b/db/versions/11152-goldenRaphis/00-firstScript.sql new file mode 100644 index 000000000..ad58a570a --- /dev/null +++ b/db/versions/11152-goldenRaphis/00-firstScript.sql @@ -0,0 +1,3 @@ +-- Place your SQL code here +ALTER TABLE vn.ticketSms__ DROP FOREIGN KEY IF EXISTS ticketSms_FK; +ALTER TABLE vn.ticketSms__ ADD CONSTRAINT ticketSms_FK FOREIGN KEY (smsFk) REFERENCES vn.sms(id) ON DELETE CASCADE ON UPDATE CASCADE; From 8f41546829f4bcf59eb9c720ef2e65168d1172f6 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 15 Jul 2024 14:25:42 +0200 Subject: [PATCH 2/9] feat: refs #7222 --- db/routines/vn/procedures/clean.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 613139fc7..0799c8fda 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -31,7 +31,7 @@ BEGIN DELETE cs.* FROM sms s JOIN clientSms cs ON cs.smsFk = s.id - WHERE s. created < v18Months; + WHERE s.created < v18Months; DELETE FROM sms WHERE created < v18Months; DELETE FROM saleTracking WHERE created < v1Years; DELETE FROM productionError WHERE dated < v1Years; From 0fb882e6886fffedb3fed642b2855d03c8959433 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 15 Jul 2024 14:55:11 +0200 Subject: [PATCH 3/9] feat: refs #7722 changes required --- db/routines/vn/procedures/clean.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/clean.sql b/db/routines/vn/procedures/clean.sql index 0799c8fda..f479d5b3e 100644 --- a/db/routines/vn/procedures/clean.sql +++ b/db/routines/vn/procedures/clean.sql @@ -28,7 +28,7 @@ BEGIN DELETE FROM ticketDown WHERE created < util.yesterday(); DELETE FROM entryLog WHERE creationDate < v2Months; DELETE IGNORE FROM expedition WHERE created < v26Months; - DELETE cs.* + DELETE cs FROM sms s JOIN clientSms cs ON cs.smsFk = s.id WHERE s.created < v18Months; From c086de264489f3aa6e91a3d7d098596b2fc3cebc Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 11:38:44 +0200 Subject: [PATCH 4/9] hotFix itemShelvingSale refs #6861 --- db/versions/11157-limeDendro/00-firstScript.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/versions/11157-limeDendro/00-firstScript.sql diff --git a/db/versions/11157-limeDendro/00-firstScript.sql b/db/versions/11157-limeDendro/00-firstScript.sql new file mode 100644 index 000000000..21071ee3f --- /dev/null +++ b/db/versions/11157-limeDendro/00-firstScript.sql @@ -0,0 +1,11 @@ + +ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_3; +ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_2; +ALTER TABLE vn.sectorCollectionSaleGroup DROP KEY saleGroupFk; + + +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_saleGroup_FK + FOREIGN KEY (saleGroupFk) REFERENCES vn.saleGroup(id) ON DELETE CASCADE ON UPDATE CASCADE; + + +ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_unique UNIQUE KEY (sectorCollectionFk,saleGroupFk); \ No newline at end of file From 3f297acbd388cc7388d284e4abfb0b63f10c9266 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 16 Jul 2024 13:06:04 +0200 Subject: [PATCH 5/9] hotFix itemShelvingSale refs #6861 --- db/versions/11157-limeDendro/00-firstScript.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/versions/11157-limeDendro/00-firstScript.sql b/db/versions/11157-limeDendro/00-firstScript.sql index 21071ee3f..fa13f14a2 100644 --- a/db/versions/11157-limeDendro/00-firstScript.sql +++ b/db/versions/11157-limeDendro/00-firstScript.sql @@ -1,11 +1,11 @@ -ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_3; -ALTER TABLE vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_2; -ALTER TABLE vn.sectorCollectionSaleGroup DROP KEY saleGroupFk; +ALTER TABLE IF EXISTS vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_3; +ALTER TABLE IF EXISTS vn.sectorCollectionSaleGroup DROP FOREIGN KEY sectorCollectionSaleGroup_ibfk_2; +ALTER TABLE IF EXISTS vn.sectorCollectionSaleGroup DROP KEY saleGroupFk; -ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_saleGroup_FK +ALTER TABLE IF EXISTS vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_saleGroup_FK FOREIGN KEY (saleGroupFk) REFERENCES vn.saleGroup(id) ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_unique UNIQUE KEY (sectorCollectionFk,saleGroupFk); \ No newline at end of file +ALTER TABLE IF EXISTS vn.sectorCollectionSaleGroup ADD CONSTRAINT sectorCollectionSaleGroup_unique UNIQUE KEY (sectorCollectionFk,saleGroupFk); \ No newline at end of file From 0ea69427ecfff06efb288206340747b4b2545035 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 17 Jul 2024 08:16:01 +0200 Subject: [PATCH 6/9] feat: refs #6403 add cancelShipment on deleteExpeditions --- back/methods/mrw-config/cancelShipment.js | 5 +++-- .../methods/expedition/deleteExpeditions.js | 20 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 10d556575..57b764858 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -13,7 +13,7 @@ module.exports = Self => { required: true }], returns: { - type: ['object'], + type: 'boolean', root: true }, http: { @@ -39,6 +39,7 @@ module.exports = Self => { const xmlString = response.data; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - return xmlDoc.getElementsByTagName('Mensaje')[0].textContent; + const [{textContent}] = xmlDoc.getElementsByTagName('Mensaje'); + return textContent.toLowerCase().includes('se ha cancelado correctamente'); }; }; diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index 55ca474d7..90a649425 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -44,15 +44,21 @@ module.exports = Self => { const expedition = await models.Expedition.findOne(filter); const {code} = expedition.agencyMode(); + let isDeleted = true; - if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') { - const isDeleted = await models.ViaexpressConfig.deleteExpedition(expeditionId); + if (code?.toLowerCase()?.includes('mrw')) { + const result = await models.MrwConfig.cancelShipment(expeditionId); + isDeleted = result; + } - if (isDeleted === 'true') { - const deletedExpedition = await models.Expedition.destroyById(expeditionId); - deletedExpeditions.push(deletedExpedition); - } else notDeletedExpeditions.push(expeditionId); - } else { + if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') { + const result = await models.ViaexpressConfig.deleteExpedition(expeditionId); + if (result !== 'true') isDeleted = false; + } + + if (!isDeleted) + notDeletedExpeditions.push(expeditionId); + else { const deletedExpedition = await models.Expedition.destroyById(expeditionId); deletedExpeditions.push(deletedExpedition); } From f83dd37a28d891083d3ea3828cde70a5da8cd51d Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 17 Jul 2024 08:23:33 +0200 Subject: [PATCH 7/9] fix: refs #6403 remove line --- modules/ticket/back/methods/expedition/deleteExpeditions.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index 90a649425..1255f19b8 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -46,10 +46,8 @@ module.exports = Self => { const {code} = expedition.agencyMode(); let isDeleted = true; - if (code?.toLowerCase()?.includes('mrw')) { - const result = await models.MrwConfig.cancelShipment(expeditionId); - isDeleted = result; - } + if (code?.toLowerCase()?.includes('mrw')) + isDeleted = await models.MrwConfig.cancelShipment(expeditionId); if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') { const result = await models.ViaexpressConfig.deleteExpedition(expeditionId); From 4ff388198b0fada3b022004dc618768a6e0a7b8a Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 17 Jul 2024 10:14:41 +0200 Subject: [PATCH 8/9] fix(deletExpeditions): add try catch --- .../methods/expedition/deleteExpeditions.js | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index 1255f19b8..75993a485 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -27,38 +27,33 @@ module.exports = Self => { const deletedExpeditions = []; for (let expeditionId of expeditionIds) { - const filter = { - fields: [], - where: { - id: expeditionId - }, - include: [ - { - relation: 'agencyMode', - scope: { - fields: ['code'], + try { + const expedition = await models.Expedition.findById(expeditionId, { + include: [ + { + relation: 'agencyMode', + scope: { + fields: ['code'], + } } - } - ] - }; + ] + }); + const {code} = expedition.agencyMode(); - const expedition = await models.Expedition.findOne(filter); - const {code} = expedition.agencyMode(); - let isDeleted = true; + if (code?.toLowerCase()?.includes('mrw') && expedition.externalId) { + const result = await models.MrwConfig.cancelShipment(expeditionId); + if (!result) throw new Error('not deleted'); + } - if (code?.toLowerCase()?.includes('mrw')) - isDeleted = await models.MrwConfig.cancelShipment(expeditionId); + if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') { + const result = await models.ViaexpressConfig.deleteExpedition(expeditionId); + if (result !== 'true') throw new Error('not deleted'); + } - if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') { - const result = await models.ViaexpressConfig.deleteExpedition(expeditionId); - if (result !== 'true') isDeleted = false; - } - - if (!isDeleted) - notDeletedExpeditions.push(expeditionId); - else { const deletedExpedition = await models.Expedition.destroyById(expeditionId); deletedExpeditions.push(deletedExpedition); + } catch (e) { + notDeletedExpeditions.push(expeditionId); } } From 563c70c65d882833c3550ed54c7a2364f791da49 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 17 Jul 2024 11:18:12 +0200 Subject: [PATCH 9/9] fix(cancelShipment): fix --- back/methods/mrw-config/cancelShipment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 57b764858..56d206529 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -39,7 +39,7 @@ module.exports = Self => { const xmlString = response.data; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - const [{textContent}] = xmlDoc.getElementsByTagName('Mensaje'); - return textContent.toLowerCase().includes('se ha cancelado correctamente'); + const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; + return result.toLowerCase().includes('se ha cancelado correctamente'); }; };