40 lines
984 B
JavaScript
40 lines
984 B
JavaScript
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();
|
|
});
|
|
}
|
|
};
|
|
};
|