module.exports = Self => { Self.remoteMethod('sumAmount', { description: 'Returns the sum of invoices amount for a client', accessType: 'READ', accepts: [{ arg: 'id', description: 'The client Id', type: 'number', required: true, http: {source: 'path'} }], returns: { arg: 'sumAmount', type: 'number' }, http: { path: `/:id/sumAmount`, verb: 'GET' } }); Self.sumAmount = async id => { let query = `SELECT SUM(amount) AS sumAmount FROM vn.invoiceOut WHERE clientFk = ?`; let result = await Self.rawSql(query, [id]); return result[0].sumAmount; }; };