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

37 lines
1.2 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 isManaExcluded = await models.WorkerManaExcluded.findById(userId, null, myOptions);
if (isManaExcluded) return false;
const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions);
2023-06-01 06:32:06 +00:00
const departments = await models.Department.getLeaves(ctx, salesDepartment.id, null, myOptions);
2022-10-21 06:00:24 +00:00
const workerDepartment = await models.WorkerDepartment.findById(userId, null, myOptions);
if (!workerDepartment) return false;
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
2024-10-15 13:43:12 +00:00
return !!usesMana;
};
};