From 01537d410ccda58d453b722f9e6b3f780dd852df Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 27 Nov 2024 13:08:14 +0100 Subject: [PATCH 1/3] feat: refs #6629 refs # 6629 updateAddress --- .../client/back/methods/client/updateAddress.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index 7342b28f1..190ebbc63 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -72,6 +72,10 @@ module.exports = function(Self) { { arg: 'isLogifloraAllowed', type: 'boolean' + }, + { + arg: 'updateObservations', + type: 'boolean' } ], returns: { @@ -127,6 +131,17 @@ module.exports = function(Self) { delete args.ctx; // Remove unwanted properties const updatedAddress = await address.updateAttributes(ctx.args, myOptions); + if (args.updateObservations) { + const ticket = await Self.rawSql(` + UPDATE ticketObservation to2 + JOIN ticket t ON t.id = to2.ticketFk + JOIN address a ON a.id = t.addressFk + JOIN addressObservation ao ON ao.addressFk = a.id + SET to2.description = ao.description + WHERE ao.observationTypeFk = to2.observationTypeFk + AND a.id = ? + AND t.shipped >= util.VN_CURDATE()`, [addressId]); + } return updatedAddress; }; -- 2.40.1 From 849bcd1ff55633de28469dfd812b21a6cb9805b6 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 14 Jan 2025 13:39:43 +0100 Subject: [PATCH 2/3] feat: refs #6629 test back updateObservations --- .../client/specs/updateAddress.spec.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index 0453332d7..e8d6bb8d8 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -157,4 +157,57 @@ describe('Address updateAddress', () => { throw e; } }); + + fit('should update ticket observations when updateObservations is true', async() => { + const tx = await models.Client.beginTransaction({}); + const client = 1103; + const address = 123; + const ticket = 31; + const observationType = 3; + + const salesAssistantId = 21; + const addressObservation = 'nuevo texto'; + const ticketObservation = 'texto a modificar'; + + try { + const options = {transaction: tx}; + ctx.req.accessToken.userId = salesAssistantId; + ctx.args = { + updateObservations: true, + incotermsFk: incotermsId, + provinceFk: provinceId, + customsAgentFk: customAgentOneId + }; + + await models.AddressObservation.create({ + addressFk: address, + observationTypeFk: observationType, + description: addressObservation + }, options); + + await models.TicketObservation.create({ + ticketFk: ticket, + observationTypeFk: observationType, + description: ticketObservation + }, options); + + await models.Client.updateAddress(ctx, client, address, options); + + const updatedObservation = await models.TicketObservation.findOne({ + where: {ticketFk: ticket, observationTypeFk: observationType} + }, options); + + // const address = await models.Address.findById(addressId, null, options); + + // const addressObservation = await models.addressObservation.findById(addressId, null, options); + + expect(updatedObservation).toEqual(addressObservation); + // expect(1).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); -- 2.40.1 From 807ddf07ad33b8fd77aa81b0ddb5d31b3190ecfb Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 15 Jan 2025 07:31:49 +0100 Subject: [PATCH 3/3] feat: refs #6629 test back --- .../back/methods/client/specs/updateAddress.spec.js | 9 ++------- modules/client/back/methods/client/updateAddress.js | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index e8d6bb8d8..233ab9ccb 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -158,7 +158,7 @@ describe('Address updateAddress', () => { } }); - fit('should update ticket observations when updateObservations is true', async() => { + it('should update ticket observations when updateObservations is true', async() => { const tx = await models.Client.beginTransaction({}); const client = 1103; const address = 123; @@ -197,12 +197,7 @@ describe('Address updateAddress', () => { where: {ticketFk: ticket, observationTypeFk: observationType} }, options); - // const address = await models.Address.findById(addressId, null, options); - - // const addressObservation = await models.addressObservation.findById(addressId, null, options); - - expect(updatedObservation).toEqual(addressObservation); - // expect(1).toEqual(1); + expect(updatedObservation.description).toEqual(addressObservation); await tx.rollback(); } catch (e) { diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index 69e288db3..e6e5adb45 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -148,7 +148,7 @@ module.exports = function(Self) { SET to2.description = ao.description WHERE ao.observationTypeFk = to2.observationTypeFk AND a.id = ? - AND t.shipped >= util.VN_CURDATE()`, [addressId]); + AND t.shipped >= util.VN_CURDATE()`, [addressId], myOptions); } return updatedAddress; -- 2.40.1