2017-12-04 07:17:29 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('sumAmount', {
|
2018-01-29 11:37:54 +00:00
|
|
|
description: 'Returns the sum of greuge for a client',
|
2017-12-04 07:17:29 +00:00
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'clientFk',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
arg: 'sumAmount'
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/sumAmount`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-08 13:53:30 +00:00
|
|
|
Self.sumAmount = async(clientFk, options) => {
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
const query = `SELECT SUM(amount) AS sumAmount FROM vn.greuge WHERE clientFk = ?`;
|
2018-03-27 13:06:22 +00:00
|
|
|
try {
|
2021-07-08 13:53:30 +00:00
|
|
|
const [response] = await Self.rawSql(query, [clientFk], myOptions);
|
2018-03-27 13:06:22 +00:00
|
|
|
|
|
|
|
return response ? response.sumAmount : 0;
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error(e);
|
|
|
|
}
|
2017-12-04 07:17:29 +00:00
|
|
|
};
|
|
|
|
};
|