salix/services/client/common/methods/greuge/sumAmount.js

32 lines
876 B
JavaScript
Raw Normal View History

2017-12-04 07:17:29 +00:00
module.exports = Self => {
Self.remoteMethod('sumAmount', {
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'
}
});
Self.sumAmount = (clientFk, callback) => {
let query = `SELECT SUM(amount) AS sumAmount FROM vn.greuge WHERE clientFk = ?`;
Self.rawSql(query, [clientFk])
.then(response => {
callback(null, response.length ? response[0].sumAmount : 0);
})
.catch(err => {
callback(err);
});
2017-12-04 07:17:29 +00:00
};
};