From b7e84f43decbff0d4c45c6a64e116b2c605ec2e3 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 16 Jul 2024 13:26:20 +0200 Subject: [PATCH 1/2] feat: refs #6403 add delete --- back/methods/mrw-config/cancelShipment.js | 3 ++- .../methods/expedition/deleteExpeditions.js | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 10d556575..57f9a1a8a 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -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 result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; + return result.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 9e007bfb8a05fc9311bbde5440152ec3aab48144 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 16 Jul 2024 13:43:36 +0200 Subject: [PATCH 2/2] fix: refs #6403 fix mrw cancel shipment return type --- back/methods/mrw-config/cancelShipment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 57f9a1a8a..56d206529 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: {