refactor(getTransactions): lilium customer transactions
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2023-03-20 23:09:17 +01:00
parent 40ccc4f409
commit 634db7c7fc
2 changed files with 51 additions and 11 deletions

View File

@ -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"
}
}

View File

@ -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`);