39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
|
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'});
|
||
|
|
||
|
return mana.amount | 0;
|
||
|
};
|
||
|
};
|