salix/modules/ticket/back/methods/sale/usesMana.js

32 lines
1.0 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethodCtx('usesMana', {
description: 'Returns if the worker uses mana',
2022-10-21 06:00:24 +00:00
accessType: 'READ',
accepts: [],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/usesMana`,
2022-10-21 06:00:24 +00:00
verb: 'GET'
}
});
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);
2022-10-21 06:00:24 +00:00
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
return usesMana ? true : false;
};
};