const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethod('getTransactions', { description: 'Returns last entries', accessType: 'READ', accepts: [{ arg: 'filter', type: 'Object', description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', http: {source: 'query'} }], returns: { type: ['Object'], root: true }, http: { path: `/getTransactions`, verb: 'GET' } }); Self.getTransactions = async filter => { let stmt = new ParameterizedSQL(` SELECT t.id, t.clientFk, t.created, t.amount / 100 amount, t.receiptFk IS NOT NULL AS isConfirmed, tt.message responseMessage, te.message errorMessage FROM hedera.tpvTransaction t JOIN hedera.tpvMerchant m ON m.id = t.merchantFk LEFT JOIN hedera.tpvResponse tt ON tt.id = t.response LEFT JOIN hedera.tpvError te ON te.code = errorCode`); stmt.merge(Self.buildSuffix(filter, 't')); return await Self.rawStmt(stmt); }; };