2018-06-28 13:29:00 +00:00
|
|
|
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;
|
2018-06-28 13:29:00 +00:00
|
|
|
};
|
|
|
|
};
|