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

35 lines
952 B
JavaScript

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);
});
};
};