From 69280925944e03f1db0006ca2b60aaf3017caf63 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 26 Mar 2020 12:00:07 +0100 Subject: [PATCH] fix ticket.sale state autocomplete --- modules/ticket/back/methods/state/editableStates.js | 8 ++++++-- .../ticket/back/methods/state/specs/editableState.spec.js | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 4979f4819..c1cbda799 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -3,6 +3,10 @@ module.exports = Self => { Self.remoteMethodCtx('editableStates', { description: 'Gets the editable states according the user role ', accessType: 'READ', + accepts: { + arg: 'filter', + type: 'object' + }, returns: { type: ['Object'], root: true @@ -13,10 +17,10 @@ module.exports = Self => { } }); - Self.editableStates = async ctx => { + Self.editableStates = async(ctx, filter) => { let userId = ctx.req.accessToken.userId; let models = Self.app.models; - let statesList = await models.State.find(); + let statesList = await models.State.find({where: filter.where}); let isProduction = await models.Account.hasRole(userId, 'production'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); diff --git a/modules/ticket/back/methods/state/specs/editableState.spec.js b/modules/ticket/back/methods/state/specs/editableState.spec.js index 54dbdfcae..03cb7616c 100644 --- a/modules/ticket/back/methods/state/specs/editableState.spec.js +++ b/modules/ticket/back/methods/state/specs/editableState.spec.js @@ -1,10 +1,12 @@ const app = require('vn-loopback/server/server'); describe('ticket editableStates()', () => { + const filter = {where: {name: {like: '%%'}}}; it('should return the expected state for the given role', async() => { const productionRole = 49; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); expect(deliveredState).toBeTruthy(); @@ -13,7 +15,7 @@ describe('ticket editableStates()', () => { it(`should returns the expected states by a specific role`, async() => { const productionRole = 18; const ctx = {req: {accessToken: {userId: productionRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let deliveredState = result.some(state => state.code == 'DELIVERED'); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); @@ -24,7 +26,7 @@ describe('ticket editableStates()', () => { it(`should return again the expected state by a specific role`, async() => { const employeeRole = 1; const ctx = {req: {accessToken: {userId: employeeRole}}}; - let result = await app.models.State.editableStates(ctx); + let result = await app.models.State.editableStates(ctx, filter); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); expect(pickerDesignedState).toBeFalsy();