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

40 lines
984 B
JavaScript
Raw Normal View History

2023-11-21 11:32:36 +00:00
module.exports = Self => {
Self.remoteMethodCtx('getAvailablePrinters', {
description: 'Retrieve available printers for an user',
accessType: 'READ',
http: {
path: `/getAvailabePrinters`,
verb: 'GET'
},
returns: {
type: ['object'],
},
});
Self.getAvailablePrinters = async ctx => {
const userId = ctx.req.accessToken.userId;
const operators = await Self.find({
fields: [],
where: {
workerFk: userId,
},
include: {
relation: 'printer',
scope: {
fields: ['id', 'name']
},
where: {
isLabeler: {neq: 0}
}
}
});
if (operators.length) {
return operators.map(operator => {
return operator.printer();
});
}
};
};