salix/services/loopback/common/methods/ticket/getSalesPersonMana.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('getSalesPersonMana', {
description: 'Returns mana of a salesperson of a ticket',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}],
returns: {
root: true
},
http: {
path: `/:id/getSalesPersonMana`,
verb: 'GET'
}
});
Self.getSalesPersonMana = async ticketFk => {
let ticket = await Self.app.models.Ticket.find({
where: {
id: ticketFk
},
include: [{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}],
fields: ['id', 'clientFk']
});
let mana = await Self.app.models.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'});
2018-06-29 06:07:40 +00:00
return mana ? mana.amount : 0;
};
};