#154 credito ya inserta el usuario que efectua el cambio

This commit is contained in:
Carlos Jimenez 2018-03-06 15:14:49 +01:00
parent 8ee3c18cbc
commit a47769f7c0
3 changed files with 13 additions and 2 deletions

View File

@ -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"]`,

View File

@ -72,6 +72,7 @@ describe('Add credit path', () => {
.getInnerText(selectors.clientCredit.firstCreditText)
.then(value => {
expect(value).toContain(999);
expect(value).toContain('developer');
});
});
});

View File

@ -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) {