44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
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
|
|
},
|
|
http: {
|
|
path: `/editableStates`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.editableStates = async(ctx, filter, options) => {
|
|
const models = Self.app.models;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
let statesList = await models.State.find(filter, myOptions);
|
|
const seeEditableStates = await models.ACL.checkAccessAcl(ctx, 'State', 'seeEditableStates', 'READ');
|
|
|
|
if (seeEditableStates)
|
|
return statesList;
|
|
|
|
const seeFilteredEditableStates =
|
|
await models.ACL.checkAccessAcl(ctx, 'State', 'seeFilteredEditableStates', 'READ');
|
|
|
|
if (seeFilteredEditableStates) {
|
|
return statesList = statesList.filter(stateList =>
|
|
stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED'
|
|
);
|
|
}
|
|
|
|
return statesList.filter(stateList => stateList.alertLevel === 0);
|
|
};
|
|
};
|