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

34 lines
969 B
JavaScript

const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
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 = {...(options || {})};
const seeEditableStates = await models.ACL.checkAccessAcl(ctx, 'State', 'seeEditableStates', 'READ');
if (!seeEditableStates)
filter = mergeFilters(filter, {where: {alertLevel: 0}});
const states = await models.State.find(filter, myOptions);
return states;
};
};