diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index a3c91aef2..610de5b4a 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -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); diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 21dc23abb..8125d814b 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -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); }; }; diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index 4d571312b..4ef3fd82a 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -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!')); diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index f86f7295b..f77a658c6 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -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">
diff --git a/modules/claim/front/basic-data/index.js b/modules/claim/front/basic-data/index.js index be5ab2fde..16b63767d 100644 --- a/modules/claim/front/basic-data/index.js +++ b/modules/claim/front/basic-data/index.js @@ -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: '<' } diff --git a/modules/client/back/methods/client/addressesPropagateRe.js b/modules/client/back/methods/client/addressesPropagateRe.js index b94462c93..31cafa654 100644 --- a/modules/client/back/methods/client/addressesPropagateRe.js +++ b/modules/client/back/methods/client/addressesPropagateRe.js @@ -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; };