module.exports = Self => { Self.remoteMethodCtx('usesMana', { description: 'Returns if the worker uses mana', accessType: 'WRITE', accepts: [], returns: { type: 'boolean', root: true }, http: { path: `/usesMana`, verb: 'POST' } }); Self.usesMana = async(ctx, options) => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); const workerDepartment = await models.WorkerDepartment.findById(userId); const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); return usesMana ? true : false; }; };