From a47769f7c0b466566e2ad5ffa2aa2b22f2e7800f Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 6 Mar 2018 15:14:49 +0100 Subject: [PATCH] #154 credito ya inserta el usuario que efectua el cambio --- e2e/helpers/selectors.js | 2 +- e2e/paths/client-module/09_add_credit.spec.js | 1 + services/loopback/common/models/client.js | 12 +++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index c723c764b..e592c8e87 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -127,7 +127,7 @@ export default { addCreditFloatButton: `${components.vnFloatButton}`, creditInput: `${components.vnTextfield}[name="credit"]`, saveButton: `${components.vnSubmit}`, - firstCreditText: 'vn-client-credit-list .list-element > vn-one' + firstCreditText: 'vn-client-credit-list .list-element' }, clientGreuge: { greugeButton: `${components.vnMenuItem}[ui-sref="clientCard.greuge.list"]`, diff --git a/e2e/paths/client-module/09_add_credit.spec.js b/e2e/paths/client-module/09_add_credit.spec.js index ca0804fff..c5ad8088d 100644 --- a/e2e/paths/client-module/09_add_credit.spec.js +++ b/e2e/paths/client-module/09_add_credit.spec.js @@ -72,6 +72,7 @@ describe('Add credit path', () => { .getInnerText(selectors.clientCredit.firstCreditText) .then(value => { expect(value).toContain(999); + expect(value).toContain('developer'); }); }); }); diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index 16c1a8949..7a26ce6ff 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -97,12 +97,22 @@ module.exports = function(Self) { throw new UserError('Unable to mark the equivalence surcharge'); } - if (changes.credit !== undefined) + if (changes.credit !== undefined) { try { await validateCreditChange(ctx, finalState); } catch (e) { throw new UserError('You are not allowed to change the credit'); } + let filter = {fields: ['id'], where: {userFk: ctx.options.accessToken.userId}}; + let worker = await Self.app.models.Worker.findOne(filter); + + let newCredit = { + amount: changes.credit, + clientFk: finalState.id, + workerFk: worker ? worker.id : null + }; + await Self.app.models.ClientCredit.create(newCredit); + } }); async function validateCreditChange(ctx, finalState) {