fix ticket.sale state autocomplete
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-03-26 12:00:07 +01:00
parent efcecd0995
commit 6928092594
2 changed files with 11 additions and 5 deletions

View File

@ -3,6 +3,10 @@ module.exports = Self => {
Self.remoteMethodCtx('editableStates', { Self.remoteMethodCtx('editableStates', {
description: 'Gets the editable states according the user role ', description: 'Gets the editable states according the user role ',
accessType: 'READ', accessType: 'READ',
accepts: {
arg: 'filter',
type: 'object'
},
returns: { returns: {
type: ['Object'], type: ['Object'],
root: true 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 userId = ctx.req.accessToken.userId;
let models = Self.app.models; 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 isProduction = await models.Account.hasRole(userId, 'production');
let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');

View File

@ -1,10 +1,12 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('ticket editableStates()', () => { describe('ticket editableStates()', () => {
const filter = {where: {name: {like: '%%'}}};
it('should return the expected state for the given role', async() => { it('should return the expected state for the given role', async() => {
const productionRole = 49; const productionRole = 49;
const ctx = {req: {accessToken: {userId: productionRole}}}; 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 deliveredState = result.some(state => state.code == 'DELIVERED');
expect(deliveredState).toBeTruthy(); expect(deliveredState).toBeTruthy();
@ -13,7 +15,7 @@ describe('ticket editableStates()', () => {
it(`should returns the expected states by a specific role`, async() => { it(`should returns the expected states by a specific role`, async() => {
const productionRole = 18; const productionRole = 18;
const ctx = {req: {accessToken: {userId: productionRole}}}; 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 deliveredState = result.some(state => state.code == 'DELIVERED');
let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED'); 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() => { it(`should return again the expected state by a specific role`, async() => {
const employeeRole = 1; const employeeRole = 1;
const ctx = {req: {accessToken: {userId: employeeRole}}}; 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'); let pickerDesignedState = result.some(state => state.code == 'PICKER_DESIGNED');
expect(pickerDesignedState).toBeFalsy(); expect(pickerDesignedState).toBeFalsy();