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

29 lines
727 B
JavaScript

module.exports = Self => {
Self.remoteMethod('getTotal', {
description: 'Returns the total of a ticket',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}],
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/getTotal`,
verb: 'GET'
}
});
Self.getTotal = async ticketFk => {
let query = `SELECT vn.ticketGetTotal(?) AS amount`;
let [total] = await Self.rawSql(query, [ticketFk]);
return total.amount ? total.amount : 0.00;
};
};