2018-09-28 13:00:12 +00:00
|
|
|
|
|
|
|
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 => {
|
2018-11-07 13:20:58 +00:00
|
|
|
let conn = Self.dataSource.connector;
|
2018-09-28 13:00:12 +00:00
|
|
|
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`);
|
|
|
|
|
2018-11-07 13:20:58 +00:00
|
|
|
stmt.merge(conn.makeSuffix(filter, 't'));
|
2018-09-28 13:00:12 +00:00
|
|
|
|
|
|
|
return await Self.rawStmt(stmt);
|
|
|
|
};
|
|
|
|
};
|