From d51c9fc12061bd612fd48697fe22ad4decfaf108 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 20 May 2024 12:14:59 +0200 Subject: [PATCH 1/3] fix: refs #6404 fix cancel shipment --- back/methods/mrw-config/cancelShipment.js | 4 ++-- back/methods/mrw-config/createShipment.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 218b6a96b..dd33694ea 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -39,8 +39,8 @@ module.exports = Self => { const xmlString = response.data; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - const [resultElement] = xmlDoc.getElementsByTagName('Mensaje'); + const resultElement = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; - return resultElement.textContent; + return resultElement; }; }; diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 12263de03..7d226a5bc 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -42,7 +42,8 @@ module.exports = Self => { throw new UserError(`Some mrwConfig parameters are not set`); const query = - `SELECT CASE co.code + `SELECT + CASE co.code WHEN 'ES' THEN a.postalCode WHEN 'PT' THEN LEFT(a.postalCode, 4) WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00') From 143f9cf0bbbdf93e539ff15ae8db887096687a6e Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 20 May 2024 12:17:10 +0200 Subject: [PATCH 2/3] fix: refs #6404 fix return --- back/methods/mrw-config/cancelShipment.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index dd33694ea..86bbb7410 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -39,8 +39,6 @@ module.exports = Self => { const xmlString = response.data; const parser = new DOMParser(); const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); - const resultElement = xmlDoc.getElementsByTagName('Mensaje')[0].textContent; - - return resultElement; + return xmlDoc.getElementsByTagName('Mensaje')[0].textContent; }; }; From 3fa557f90d1e5adaefc826c74b2356ee836d62ea Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 20 May 2024 13:58:32 +0200 Subject: [PATCH 3/3] fix: refs #6404 create shipment --- back/methods/mrw-config/createShipment.js | 11 +++-------- back/methods/mrw-config/specs/createShipment.spec.js | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 7d226a5bc..081a83382 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -90,14 +90,9 @@ module.exports = Self => { const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml'); const file = getTextByTag(getLabelResponse, 'EtiquetaFile'); - try { - await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions); - if (tx) await tx.commit(); - } catch (error) { - if (tx) await tx.rollback(); - throw error; - } - return file; + if (tx) await tx.commit(); + + return {shipmentId, file}; }; function getTextByTag(xmlDoc, tag) { diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 0f48bc2d3..f05f9a81d 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -81,9 +81,9 @@ describe('MRWConfig createShipment()', () => { spyOn(axios, 'post').and.callFake(() => Promise.resolve(mockPostResponses.pop())); - const base64Binary = await models.MrwConfig.createShipment(expedition1.id, options); + const {file} = await models.MrwConfig.createShipment(expedition1.id, options); - expect(base64Binary).toEqual(mockBase64Binary); + expect(file).toEqual(mockBase64Binary); }); it('should fail if mrwConfig has no data', async() => {