Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
69a176a661
|
@ -24,7 +24,6 @@ describe('Update Claim', () => {
|
|||
|
||||
it('should throw error if isSaleAssistant is false and try to modify a forbidden field', async() => {
|
||||
let params = {
|
||||
id: newInstance.id,
|
||||
ticketFk: 3,
|
||||
clientFk: 101,
|
||||
ticketCreated: newDate,
|
||||
|
@ -40,7 +39,7 @@ describe('Update Claim', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
await app.models.Claim.updateClaim(ctx, params)
|
||||
await app.models.Claim.updateClaim(ctx, newInstance.id, params)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
});
|
||||
|
@ -50,7 +49,6 @@ describe('Update Claim', () => {
|
|||
|
||||
it('should throw error if isSaleAssistant is false and try to modify a valid field but a forbidden stated', async() => {
|
||||
let params = {
|
||||
id: newInstance.id,
|
||||
ticketFk: 3,
|
||||
clientFk: 101,
|
||||
ticketCreated: newDate,
|
||||
|
@ -65,7 +63,7 @@ describe('Update Claim', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
await app.models.Claim.updateClaim(ctx, params)
|
||||
await app.models.Claim.updateClaim(ctx, newInstance.id, params)
|
||||
.catch(e => {
|
||||
error = e;
|
||||
});
|
||||
|
@ -75,7 +73,6 @@ describe('Update Claim', () => {
|
|||
|
||||
it('should change field observation', async() => {
|
||||
let params = {
|
||||
id: newInstance.id,
|
||||
ticketCreated: newDate,
|
||||
observation: 'another3'
|
||||
};
|
||||
|
@ -86,7 +83,7 @@ describe('Update Claim', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
await app.models.Claim.updateClaim(ctx, params);
|
||||
await app.models.Claim.updateClaim(ctx, newInstance.id, params);
|
||||
|
||||
let claimUpdated = await app.models.Claim.findById(newInstance.id);
|
||||
|
||||
|
@ -95,7 +92,6 @@ describe('Update Claim', () => {
|
|||
|
||||
it('should change sensible fields as salesAssistant', async() => {
|
||||
let params = {
|
||||
id: newInstance.id,
|
||||
ticketFk: 3,
|
||||
clientFk: 101,
|
||||
ticketCreated: newDate,
|
||||
|
@ -112,7 +108,7 @@ describe('Update Claim', () => {
|
|||
}
|
||||
}
|
||||
};
|
||||
await app.models.Claim.updateClaim(ctx, params);
|
||||
await app.models.Claim.updateClaim(ctx, newInstance.id, params);
|
||||
|
||||
let claimUpdated = await app.models.Claim.findById(newInstance.id);
|
||||
|
||||
|
|
|
@ -7,6 +7,12 @@ module.exports = Self => {
|
|||
description: 'Update a claim with privileges',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Client id',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'params',
|
||||
type: 'object',
|
||||
required: true,
|
||||
|
@ -18,22 +24,21 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/updateClaim`,
|
||||
path: `/:id/updateClaim`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateClaim = async(ctx, params) => {
|
||||
Self.updateClaim = async(ctx, id, params) => {
|
||||
let models = Self.app.models;
|
||||
let isSalesAssistant;
|
||||
let token = ctx.req.accessToken;
|
||||
let currentUserId = token && token.userId;
|
||||
let currentUserId = ctx.req.accessToken.userId;
|
||||
|
||||
isSalesAssistant = await models.Account.hasRole(currentUserId, 'SalesAssistant');
|
||||
|
||||
if (!isSalesAssistant) {
|
||||
let oldClaim = await models.Claim.findById(params.id);
|
||||
let notModifiable = ['responsibility', 'isChargedToMana'];
|
||||
let oldClaim = await models.Claim.findById(id);
|
||||
let notModifiable = ['id', 'responsibility', 'isChargedToMana'];
|
||||
let changedFields = diff(oldClaim, params);
|
||||
let changedFieldsPicked = pick(changedFields, notModifiable);
|
||||
let statesViables = ['Gestionado', 'Pendiente', 'Anulado'];
|
||||
|
@ -45,6 +50,7 @@ module.exports = Self => {
|
|||
throw new UserError(`You don't have enough privileges to change that field`);
|
||||
}
|
||||
|
||||
return await Self.updateAll({id: params.id}, params);
|
||||
let claim = await Self.findById(id);
|
||||
return await claim.updateAttributes(params);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -147,7 +147,7 @@ class Controller {
|
|||
}
|
||||
|
||||
saveResponsibility(value) {
|
||||
let query = `/claim/api/Claims/updateClaim`;
|
||||
let query = `/api/Claims/${this.$stateParams.id}/updateClaim`;
|
||||
|
||||
this.$http.post(query, {responsibility: value}).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
vn-id="watcher"
|
||||
data="$ctrl.claim"
|
||||
form="form"
|
||||
url="/claim/api/Claims/updateClaim"
|
||||
url="/api/Claims/{{$ctrl.$stateParams.id}}/updateClaim"
|
||||
save="post">
|
||||
</vn-watcher>
|
||||
<form name="form" ng-submit="watcher.submit()" compact>
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
import ngModule from '../module';
|
||||
import './style.scss';
|
||||
|
||||
class Controller {
|
||||
constructor($stateParams) {
|
||||
this.$stateParams = $stateParams;
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$stateParams'];
|
||||
|
||||
ngModule.component('vnClaimBasicData', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
claim: '<'
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ module.exports = function(Self) {
|
|||
}
|
||||
});
|
||||
|
||||
Self.addressesPropagateRe = async (id, data) => {
|
||||
Self.addressesPropagateRe = async(id, data) => {
|
||||
if (data.hasOwnProperty('isEqualizated')) {
|
||||
await Self.app.models.Address.updateAll({clientFk: id}, data);
|
||||
let client = await Self.app.models.Client.findById(id)
|
||||
await client.updateAttributes({hasToInvoiceByAddress: false});
|
||||
return true;
|
||||
let client = await Self.app.models.Client.findById(id);
|
||||
if (client) {
|
||||
await Self.app.models.Address.updateAll({clientFk: id}, data);
|
||||
await client.updateAttributes({hasToInvoiceByAddress: false});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue