Merge pull request '5241-virtual_pos' (!1399) from 5241-virtual_pos into dev
gitea/salix/pipeline/head There was a failure building this commit Details

Reviewed-on: #1399
Reviewed-by: Vicent Llopis <vicent@verdnatura.es>
This commit is contained in:
Joan Sanchez 2023-03-21 09:35:19 +00:00
commit 46b40c03a7
7 changed files with 188 additions and 123 deletions

View File

@ -5,5 +5,6 @@
"editor.codeActionsOnSave": { "editor.codeActionsOnSave": {
"source.fixAll.eslint": true "source.fixAll.eslint": true
}, },
"search.useIgnoreFiles": false "search.useIgnoreFiles": false,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
} }

View File

@ -1,49 +0,0 @@
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);
};
};

View File

@ -1,21 +0,0 @@
const models = require('vn-loopback/server/server').models;
describe('Client getTransations', () => {
it('should call getTransations() method to receive a list of Web Payments from Bruce Wayne', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const filter = {where: {clientFk: 1101}};
const result = await models.Client.getTransactions(filter, options);
expect(result[1].id).toBeTruthy();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,66 @@
const models = require('vn-loopback/server/server').models;
describe('Client transactions', () => {
it('should call transactions() method to receive a list of Web Payments from Bruce Wayne', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {};
const filter = {where: {clientFk: 1101}};
const result = await models.Client.transactions(ctx, filter, options);
expect(result[1].id).toBeTruthy();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should call transactions() method filtering by orderFk', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {args: {orderFk: 6}};
const filter = {};
const result = await models.Client.transactions(ctx, filter, options);
const firstRow = result[0];
expect(result.length).toEqual(1);
expect(firstRow.id).toEqual(6);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
it('should call transactions() method filtering by amount', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const ctx = {args: {amount: 40}};
const filter = {};
const result = await models.Client.transactions(ctx, filter, options);
const randomIndex = Math.floor(Math.random() * result.length);
const transaction = result[randomIndex];
expect(transaction.amount).toEqual(40);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,84 @@
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.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'}
},
{
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: `/transactions`,
verb: 'GET'
}
});
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(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`);
stmt.merge(conn.makeSuffix(filter, 't'));
return Self.rawStmt(stmt, myOptions);
};
};

View File

@ -13,7 +13,7 @@ module.exports = Self => {
require('../methods/client/getCard')(Self); require('../methods/client/getCard')(Self);
require('../methods/client/getDebt')(Self); require('../methods/client/getDebt')(Self);
require('../methods/client/getMana')(Self); require('../methods/client/getMana')(Self);
require('../methods/client/getTransactions')(Self); require('../methods/client/transactions')(Self);
require('../methods/client/hasCustomerRole')(Self); require('../methods/client/hasCustomerRole')(Self);
require('../methods/client/isValidClient')(Self); require('../methods/client/isValidClient')(Self);
require('../methods/client/lastActiveTickets')(Self); require('../methods/client/lastActiveTickets')(Self);

View File

@ -1,15 +1,7 @@
<vn-crud-model <vn-crud-model vn-id="model" url="clients/transactions" link="{clientFk: $ctrl.$params.id}" limit="20"
vn-id="model" data="transactions" order="created DESC" auto-load="true">
url="clients/getTransactions"
link="{clientFk: $ctrl.$params.id}"
limit="20"
data="transactions"
order="created DESC"
auto-load="true">
</vn-crud-model> </vn-crud-model>
<vn-data-viewer <vn-data-viewer model="model" class="vn-w-md">
model="model"
class="vn-w-md">
<vn-card> <vn-card>
<vn-table model="model"> <vn-table model="model">
<vn-thead> <vn-thead>
@ -24,27 +16,19 @@
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="transaction in transactions"> <vn-tr ng-repeat="transaction in transactions">
<vn-td shrink> <vn-td shrink>
<vn-icon <vn-icon vn-tooltip="{{::$ctrl.getFormattedMessage(transaction)}}"
vn-tooltip="{{::$ctrl.getFormattedMessage(transaction)}}"
ng-show="::((transaction.errorMessage || transaction.responseMessage) && !transaction.isConfirmed)" ng-show="::((transaction.errorMessage || transaction.responseMessage) && !transaction.isConfirmed)"
icon="clear"> icon="clear">
</vn-icon> </vn-icon>
<vn-icon <vn-icon vn-tooltip="Confirmed" ng-show="::(transaction.isConfirmed)" icon="check">
vn-tooltip="Confirmed"
ng-show="::(transaction.isConfirmed)"
icon="check">
</vn-icon> </vn-icon>
</vn-td> </vn-td>
<vn-td number>{{::transaction.id}}</vn-td> <vn-td number>{{::transaction.id}}</vn-td>
<vn-td>{{::transaction.created | date:'dd/MM/yyyy HH:mm'}}</vn-td> <vn-td>{{::transaction.created | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td number>{{::transaction.amount | currency: 'EUR':2}}</vn-td> <vn-td number>{{::transaction.amount | currency: 'EUR':2}}</vn-td>
<vn-td shrink> <vn-td shrink>
<vn-icon-button <vn-icon-button icon="done_all" vn-acl="administrative" vn-acl-action="remove"
icon="done_all" translate-attr="{title: 'Confirm transaction'}" ng-show="::!transaction.isConfirmed"
vn-acl="administrative"
vn-acl-action="remove"
translate-attr="{title: 'Confirm transaction'}"
ng-show="::!transaction.isConfirmed"
ng-click="$ctrl.confirm(transaction)"> ng-click="$ctrl.confirm(transaction)">
</vn-icon-button> </vn-icon-button>
</vn-td> </vn-td>