28 lines
778 B
JavaScript
28 lines
778 B
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('getAverageInvoiced', {
|
||
|
description: 'Returns the annual average invoiced of a client',
|
||
|
accessType: 'READ',
|
||
|
accepts: [{
|
||
|
arg: 'id',
|
||
|
type: 'number',
|
||
|
required: true,
|
||
|
description: 'client id',
|
||
|
http: {source: 'path'}
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'number',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:id/getAverageInvoiced`,
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.getAverageInvoiced = async clientFk => {
|
||
|
let query = `SELECT invoiced FROM vn.annualAverageInvoiced WHERE clientFk = ?`;
|
||
|
let [invoiced] = await Self.rawSql(query, [clientFk]);
|
||
|
|
||
|
return invoiced;
|
||
|
};
|
||
|
};
|