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

35 lines
952 B
JavaScript
Raw Normal View History

2017-12-04 07:17:29 +00:00
module.exports = Self => {
Self.remoteMethod('sumAmount', {
description: 'returns sum greuge.ammount from client',
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], callback).then(response => {
if (response.length) {
callback(null, response[0].sumAmount);
} else {
callback(null, 0);
}
})
.catch(reject => {
callback(reject, null);
});
};
};