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