Tarea #602 Investigar hook
This commit is contained in:
parent
5c6ab8efc3
commit
fa9c3f4759
|
@ -1,9 +1,9 @@
|
|||
<mg-ajax path="/client/api/Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
|
||||
<mg-ajax path="/client/api/Clients/{{post.params.id}}/updateBillingData" options="vnPost"></mg-ajax>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.client"
|
||||
form="form"
|
||||
save="patch">
|
||||
save="post">
|
||||
</vn-watcher>
|
||||
<form name="form" ng-submit="$ctrl.onSubmit()">
|
||||
<vn-card pad-large>
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue