diff --git a/.vscode/settings.json b/.vscode/settings.json index 82815d588..05d23f3bb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,10 @@ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, - "search.useIgnoreFiles": false + "search.useIgnoreFiles": false, + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "eslint.format.enable": true, + "[javascript]": { + "editor.defaultFormatter": "dbaeumer.vscode-eslint" + } } diff --git a/modules/client/back/methods/client/getTransactions.js b/modules/client/back/methods/client/getTransactions.js index 45183bbdc..4116f3ee1 100644 --- a/modules/client/back/methods/client/getTransactions.js +++ b/modules/client/back/methods/client/getTransactions.js @@ -1,43 +1,78 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const buildFilter = require('vn-loopback/util/filter').buildFilter; +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { - Self.remoteMethod('getTransactions', { - description: 'Returns last entries', + Self.remoteMethodCtx('transactions', { + description: 'Returns customer transactions', accessType: 'READ', - accepts: [{ - arg: 'filter', - type: 'object', - description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} - }], + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, + { + arg: 'orderFk', + type: 'number', + http: {source: 'query'} + }, + { + arg: 'clientFk', + type: 'number', + http: {source: 'query'} + }, + { + arg: 'amount', + type: 'number', + http: {source: 'query'} + } + ], returns: { type: ['object'], root: true }, http: { - path: `/getTransactions`, + path: `/transactions`, verb: 'GET' } }); - Self.getTransactions = async(filter, options) => { + Self.transactions = async(ctx, filter, options) => { + const args = ctx.args; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const where = buildFilter(args, (param, value) => { + switch (param) { + case 'orderFk': + return {'t.id': value}; + case 'clientFk': + return {'t.clientFk': value}; + case 'amount': + return {'t.amount': (value * 100)}; + } + }); + + filter = mergeFilters(args.filter, {where}); + const conn = Self.dataSource.connector; const stmt = new ParameterizedSQL(` SELECT t.id, t.clientFk, + c.name AS customerName, t.created, t.amount / 100 amount, t.receiptFk IS NOT NULL AS isConfirmed, tt.message responseMessage, te.message errorMessage FROM hedera.tpvTransaction t + JOIN client c ON c.id = t.clientFk 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`);