2022-10-20 13:05:46 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('usesMana', {
|
|
|
|
description: 'Returns if the worker uses mana',
|
2022-10-21 06:00:24 +00:00
|
|
|
accessType: 'READ',
|
2022-10-20 13:05:46 +00:00
|
|
|
accepts: [],
|
|
|
|
returns: {
|
|
|
|
type: 'boolean',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/usesMana`,
|
2022-10-21 06:00:24 +00:00
|
|
|
verb: 'GET'
|
2022-10-20 13:05:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
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);
|
2022-12-23 07:27:03 +00:00
|
|
|
if (!workerDepartment) return false;
|
|
|
|
|
2022-10-20 13:05:46 +00:00
|
|
|
const usesMana = departments.find(department => department.id == workerDepartment.departmentFk);
|
|
|
|
|
|
|
|
return usesMana ? true : false;
|
|
|
|
};
|
|
|
|
};
|