From fa9c3f4759f5e47b0c1a6f77c83ecd3f3359afef Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 18 Sep 2018 14:36:41 +0200 Subject: [PATCH] Tarea #602 Investigar hook --- client/client/src/billing-data/index.html | 4 ++-- .../client/specs/updateBillingData.spec.js | 16 +++++++--------- .../common/methods/client/updateBillingData.js | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/client/src/billing-data/index.html b/client/client/src/billing-data/index.html index 86a7ef4e4..2a2982544 100644 --- a/client/client/src/billing-data/index.html +++ b/client/client/src/billing-data/index.html @@ -1,9 +1,9 @@ - + + save="post">
diff --git a/services/loopback/common/methods/client/specs/updateBillingData.spec.js b/services/loopback/common/methods/client/specs/updateBillingData.spec.js index ad1abf4da..3c4a8afe9 100644 --- a/services/loopback/common/methods/client/specs/updateBillingData.spec.js +++ b/services/loopback/common/methods/client/specs/updateBillingData.spec.js @@ -39,21 +39,19 @@ describe('Client updateBillingData', () => { expect(error.toString()).toContain(`You don't have enough privileges to do that`); }); - it('should update the client billing data and return the count if changes made', async() => { + it('should return an error if the given IBAN is an invalid one', async() => { let ctxOfAdmin = {req: {accessToken: {userId: 5}}}; let validparams = {iban: 12345}; let idWithDataChecked = 101; + try { + await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); + } catch (error) { + expect(error.toString()).toContain('The IBAN does not have the correct format'); + } + let client = await app.models.Client.findById(idWithDataChecked); expect(client.iban).toBeFalsy(); - - let result = await app.models.Client.updateBillingData(ctxOfAdmin, validparams, idWithDataChecked); - - expect(result).toEqual({count: 1}); - - let updatedClient = await app.models.Client.findById(idWithDataChecked); - - expect(updatedClient.iban).toEqual('12345'); }); }); diff --git a/services/loopback/common/methods/client/updateBillingData.js b/services/loopback/common/methods/client/updateBillingData.js index 92fc90a87..e0abcbb25 100644 --- a/services/loopback/common/methods/client/updateBillingData.js +++ b/services/loopback/common/methods/client/updateBillingData.js @@ -24,7 +24,7 @@ module.exports = Self => { }, http: { path: `/:id/updateBillingData`, - verb: 'PATCH' + verb: 'POST' } }); @@ -32,8 +32,9 @@ module.exports = Self => { let userId = ctx.req.accessToken.userId; let isAdministrative = await Self.app.models.Account.hasRole(userId, 'administrative'); - let [taxData] = await Self.app.models.Client.find({where: {id: id}, fields: ['isTaxDataChecked']}); - if (!isAdministrative && taxData.isTaxDataChecked) + let client = await Self.app.models.Client.findOne({where: {id: id}}); + + if (!isAdministrative && client.isTaxDataChecked) throw new UserError(`You don't have enough privileges to do that`); let validUpdateParams = [ @@ -50,6 +51,13 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges to do that`); } - return await Self.app.models.Client.update({id: id}, params); + return client.updateAttributes({ + payMethodFk: params.payMethodFk, + dueDay: params.dueDay, + iban: params.iban, + hasLcr: params.hasLcr, + hasCoreVnl: params.hasCoreVnl, + hasSepaVnl: params.hasSepaVnl + }); }; };