salix/modules/ticket/back/methods/ticket/getSalesPersonMana.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('getSalesPersonMana', {
description: 'Returns the mana amount of a salesperson for a ticket',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The ticket id',
http: {source: 'path'}
}],
returns: {
root: true
},
http: {
path: `/:id/getSalesPersonMana`,
verb: 'GET'
}
});
2021-08-12 09:21:59 +00:00
Self.getSalesPersonMana = async(ticketId, options) => {
const myOptions = {};
const models = Self.app.models;
2021-08-12 09:21:59 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
const ticket = await models.Ticket.findById(ticketId, {
include: [{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}],
fields: ['id', 'clientFk']
2021-08-12 09:21:59 +00:00
}, myOptions);
2019-06-14 10:27:41 +00:00
if (!ticket) return 0;
2019-06-14 10:27:41 +00:00
const mana = await models.WorkerMana.findOne({
where: {
workerFk: ticket.client().salesPersonFk
2021-08-12 09:21:59 +00:00
},
fields: 'amount'
}, myOptions);
2018-06-29 06:07:40 +00:00
return mana ? mana.amount : 0;
};
};