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',
|
2020-03-26 11:00:07 +00:00
|
|
|
accepts: {
|
|
|
|
arg: 'filter',
|
|
|
|
type: 'object'
|
|
|
|
},
|
2019-08-08 06:33:27 +00:00
|
|
|
returns: {
|
2021-10-07 07:57:07 +00:00
|
|
|
type: ['object'],
|
2019-08-08 06:33:27 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/editableStates`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
Self.editableStates = async(ctx, filter, options) => {
|
|
|
|
const models = Self.app.models;
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
2019-08-08 06:33:27 +00:00
|
|
|
|
2023-01-30 13:13:38 +00:00
|
|
|
let statesList = await models.State.find(filter, myOptions);
|
2023-04-25 07:15:05 +00:00
|
|
|
const seeEditableStates = await models.ACL.checkAccessAcl(ctx, 'State', 'seeEditableStates', 'READ');
|
2019-08-08 06:33:27 +00:00
|
|
|
|
2023-04-25 07:15:05 +00:00
|
|
|
if (seeEditableStates)
|
2019-08-08 06:33:27 +00:00
|
|
|
return statesList;
|
|
|
|
|
2023-04-25 07:15:05 +00:00
|
|
|
const seeFilteredEditableStates =
|
|
|
|
await models.ACL.checkAccessAcl(ctx, 'State', 'seeFilteredEditableStates', 'READ');
|
|
|
|
|
|
|
|
if (seeFilteredEditableStates) {
|
2019-08-08 06:33:27 +00:00
|
|
|
return statesList = statesList.filter(stateList =>
|
|
|
|
stateList.alertLevel === 0 || stateList.code === 'PICKER_DESIGNED'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return statesList.filter(stateList => stateList.alertLevel === 0);
|
|
|
|
};
|
|
|
|
};
|