refs #5638 fix: contempla que se le pase un filtro del 'nombre'
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-05-18 08:58:13 +02:00
parent c76b84d3cb
commit 9263684ec5
1 changed files with 7 additions and 7 deletions

View File

@ -1,3 +1,4 @@
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethodCtx('editableStates', {
description: 'Gets the editable states according the user role ',
@ -19,21 +20,20 @@ module.exports = Self => {
Self.editableStates = async(ctx, filter, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const myOptions = {...(options || {})};
const isProduction = await models.VnUser.hasRole(userId, 'production', myOptions);
const isSalesPerson = await models.VnUser.hasRole(userId, 'salesPerson', myOptions);
const isAdministrative = await models.VnUser.hasRole(userId, 'administrative', myOptions);
filter.where = {alertLevel: 0};
let where = {alertLevel: 0};
if (isSalesPerson)
filter.where = {or: [{alertLevel: 0}, {code: 'PICKER_DESIGNED'}]};
where = {or: [{alertLevel: 0}, {code: 'PICKER_DESIGNED'}]};
else if (isProduction || isAdministrative)
where = undefined;
if (isProduction || isAdministrative) delete filter.where;
filter = mergeFilters(filter, {where});
return models.State.find(filter, myOptions);
};