Tarea #373, Tarea #355,Tarea #352 getSalesPersonMana

This commit is contained in:
gerard 2018-06-28 15:29:00 +02:00
parent cebb7030c5
commit 88033a7539
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
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;
};
};