From 00e5f8602064fe6c9ecf49d829ab9ecf97aeea37 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 28 Nov 2024 11:18:09 +0100 Subject: [PATCH 1/6] fix: refs #7404 add debug logging for cancelShipment and deleteExpeditions methods --- back/methods/mrw-config/cancelShipment.js | 4 ++-- modules/ticket/back/methods/expedition/deleteExpeditions.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 98aa8be39..608797d8f 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -30,6 +30,8 @@ module.exports = Self => { const clientType = await models.MrwConfig.getClientType(expeditionFk); const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8'); const renderedXml = ejs.render(template, {mrw, externalId, clientType}); + + await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', renderedXml]); const response = await axios.post(mrw.url, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' @@ -40,8 +42,6 @@ module.exports = Self => { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', xmlDoc]); - 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 75993a485..ff4a2bbad 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -52,7 +52,8 @@ module.exports = Self => { const deletedExpedition = await models.Expedition.destroyById(expeditionId); deletedExpeditions.push(deletedExpedition); - } catch (e) { + } catch (error) { + await Self.rawSql('CALL util.debugAdd(?,?);', ['deleteExpeditions', error]); notDeletedExpeditions.push(expeditionId); } } From 5923916cda07176dc3e05f97eb2e5cf58f3e8e14 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Nov 2024 11:31:38 +0100 Subject: [PATCH 2/6] fix: change debugAdd to console.error --- modules/ticket/back/methods/expedition/deleteExpeditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/expedition/deleteExpeditions.js b/modules/ticket/back/methods/expedition/deleteExpeditions.js index ff4a2bbad..267811d25 100644 --- a/modules/ticket/back/methods/expedition/deleteExpeditions.js +++ b/modules/ticket/back/methods/expedition/deleteExpeditions.js @@ -53,7 +53,7 @@ module.exports = Self => { const deletedExpedition = await models.Expedition.destroyById(expeditionId); deletedExpeditions.push(deletedExpedition); } catch (error) { - await Self.rawSql('CALL util.debugAdd(?,?);', ['deleteExpeditions', error]); + console.error('error: ', error); notDeletedExpeditions.push(expeditionId); } } From e730b5d4a14a00b47e0993e558eb539230e321e7 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Nov 2024 11:53:42 +0100 Subject: [PATCH 3/6] fix: add debugAdd response axios --- back/methods/mrw-config/cancelShipment.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 608797d8f..cd80fe4bb 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -42,6 +42,8 @@ module.exports = Self => { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); + await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipmentResponse', xmlDoc]); + const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; return result.toLowerCase().includes('se ha cancelado correctamente'); }; From 6785779fe5338ca259d051792e4135909fa86ab0 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Nov 2024 12:26:03 +0100 Subject: [PATCH 4/6] fix: add console log --- 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 cd80fe4bb..0e12909ba 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -42,7 +42,7 @@ module.exports = Self => { const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipmentResponse', xmlDoc]); + console.log('xmlDoc', xmlDoc); const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; return result.toLowerCase().includes('se ha cancelado correctamente'); From 838296e74463c9361c3280d9f1b8f50e00a7ff66 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Nov 2024 13:02:58 +0100 Subject: [PATCH 5/6] fix: add expected message result --- back/methods/mrw-config/cancelShipment.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 0e12909ba..bd483fc58 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -24,7 +24,6 @@ module.exports = Self => { Self.cancelShipment = async expeditionFk => { const models = Self.app.models; - const mrw = await models.MrwConfig.findOne(); const {externalId} = await models.Expedition.findById(expeditionFk); const clientType = await models.MrwConfig.getClientType(expeditionFk); @@ -39,12 +38,11 @@ module.exports = Self => { }); const xmlString = response.data; + await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipmentResponse', xmlString]); const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - console.log('xmlDoc', xmlDoc); - const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; - return result.toLowerCase().includes('se ha cancelado correctamente'); + return ['no se ha encontrado', 'se ha cancelado correctamente'].some(r => r.includes(result.toLowerCase())); }; }; From d6a849727e0b5dc4a60266ec5b00fb48eb20c8e4 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 28 Nov 2024 13:11:43 +0100 Subject: [PATCH 6/6] fix: fix result test --- 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 bd483fc58..e96d6d694 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -43,6 +43,6 @@ module.exports = Self => { const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; - return ['no se ha encontrado', 'se ha cancelado correctamente'].some(r => r.includes(result.toLowerCase())); + return ['no se ha encontrado', 'se ha cancelado correctamente'].some(res => result.toLowerCase().includes(res)); }; };