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

40 lines
917 B
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('getPrinter', {
description: 'Gets user\'s printer',
accessType: 'READ',
http: {
path: `/getPrinter`,
verb: 'GET'
},
returns: {
type: 'object',
},
});
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();
return {
id: printer.id,
name: printer.name
};
}
};
};