diff --git a/modules/ticket/back/methods/state/editableStates.js b/modules/ticket/back/methods/state/editableStates.js index 061097a65..eb9a1f682 100644 --- a/modules/ticket/back/methods/state/editableStates.js +++ b/modules/ticket/back/methods/state/editableStates.js @@ -24,20 +24,17 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - let statesList = await models.State.find(filter, myOptions); 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); - if (isProduction || isAdministrative) - return statesList; + filter.where = {alertLevel: 0}; - if (isSalesPerson) { - return statesList = statesList.filter(stateList => - stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED' - ); - } + if (isSalesPerson) + filter.where = {or: [{alertLevel: 0}, {code: 'PICKER_DESIGNED'}]}; - return statesList.filter(stateList => stateList.alertLevel === 0); + if (isProduction || isAdministrative) delete filter.where; + + return models.State.find(filter, myOptions); }; };