50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
|
|
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, options) => {
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const conn = Self.dataSource.connector;
|
|
const 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(conn.makeSuffix(filter, 't'));
|
|
|
|
return Self.rawStmt(stmt, myOptions);
|
|
};
|
|
};
|