salix/modules/ticket/back/methods/state/editableStates.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-08 06:33:27 +00:00
module.exports = Self => {
Self.remoteMethodCtx('editableStates', {
description: 'Gets the editable states according the user role ',
accessType: 'READ',
returns: {
type: ['Object'],
root: true
},
http: {
path: `/editableStates`,
verb: 'GET'
}
});
Self.editableStates = async ctx => {
let userId = ctx.req.accessToken.userId;
let models = Self.app.models;
let statesList = await models.State.find();
let isProduction = await models.Account.hasRole(userId, 'production');
let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson');
let isAdministrative = await models.Account.hasRole(userId, 'administrative');
if (isProduction || isAdministrative)
return statesList;
if (isSalesPerson) {
return statesList = statesList.filter(stateList =>
stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED'
);
}
return statesList.filter(stateList => stateList.alertLevel === 0);
};
};