salix/modules/worker/back/methods/operator/getPrinter.js

39 lines
923 B
JavaScript
Raw Normal View History

2023-11-21 11:32:36 +00:00
module.exports = Self => {
Self.remoteMethodCtx('getPrinter', {
description: 'Gets user\'s printer',
accessType: 'READ',
http: {
path: `/getPrinter`,
verb: 'GET'
},
returns: {
2024-01-02 11:21:25 +00:00
type: ['object'],
2024-01-02 11:44:12 +00:00
root: true
2023-11-21 11:32:36 +00:00
},
});
Self.getPrinter = async ctx => {
const userId = ctx.req.accessToken.userId;
const operator = await Self.findOne({
include: [
{
relation: 'printer',
scope: {
fields: ['id', 'name'],
}
}
],
where: {
workerFk: userId
}
});
if (operator) {
const printer = operator.printer();
2024-01-02 11:21:25 +00:00
return Array.isArray(printer) ? printer : [printer];
2023-11-21 11:32:36 +00:00
}
2024-01-02 11:44:12 +00:00
return [];
2023-11-21 11:32:36 +00:00
};
};