diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index 97d4edea7..4b658ab33 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('createFromSales', { + Self.remoteMethodCtx('createFromSales', { description: 'Create a claim', accessType: '', accepts: [{ @@ -25,10 +25,14 @@ module.exports = Self => { } }); - Self.createFromSales = async params => { + Self.createFromSales = async(ctx, params) => { let model = Self.app.models; let transaction = await Self.beginTransaction({}); try { + let userId = ctx.req.accessToken.userId; + let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); + + params.claim.workerFk = worker.id; let newClaim = await Self.create(params.claim, {transaction}); let promises = []; for (let i = 0; i < params.sales.length; i++) { diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index 6e414e88c..226aeba53 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -13,8 +13,7 @@ describe('Claim Create', () => { let newClaim = { ticketFk: 2, clientFk: 101, - ticketCreated: newDate, - workerFk: 18 + ticketCreated: newDate }; let newSale = [{ @@ -24,9 +23,10 @@ describe('Claim Create', () => { }]; let params = {claim: newClaim, sales: newSale}; + let ctx = {req: {accessToken: {userId: 1}}}; it('should create a new claim', async() => { - let claim = await app.models.Claim.createFromSales(params); + let claim = await app.models.Claim.createFromSales(ctx, params); expect(claim.ticketFk).toEqual(newClaim.ticketFk); expect(claim.clientFk).toEqual(newClaim.clientFk); @@ -44,7 +44,7 @@ describe('Claim Create', () => { it('should not be able to create a claim if exists that sale', async() => { let error; - await app.models.Claim.createFromSales(params) + await app.models.Claim.createFromSales(ctx, params) .catch(e => { error = e; diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index c3db07e58..92d3f67e5 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -180,8 +180,7 @@ class Controller { let claim = { ticketFk: this.ticket.id, clientFk: this.ticket.clientFk, - ticketCreated: this.ticket.shipped, - workerFk: this.ticket.client.salesPersonFk + ticketCreated: this.ticket.shipped }; let sales = this.getCheckedLines(); for (let i = 0; i < sales.length; i++)