From 34383908a91909050e5a5dcf37c50632d4b51b11 Mon Sep 17 00:00:00 2001 From: owl352 Date: Sat, 30 Nov 2024 21:07:39 +0300 Subject: [PATCH] fix --- packages/api/README.md | 4 ++-- .../api/src/controllers/TransactionsController.js | 11 +++-------- packages/api/src/dao/TransactionsDAO.js | 6 +++--- packages/api/src/schemas.js | 6 ++++-- packages/api/test/integration/transactions.spec.js | 8 ++++---- packages/frontend/src/app/api/content.md | 4 ++-- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/api/README.md b/packages/api/README.md index 7a1a48e3..55302d15 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -463,12 +463,12 @@ Status can be either `SUCCESS` or `FAIL`. In case of error tx, message will appe * `limit` cannot be more then 100 * `owner` Identity identifier * `status` can be `SUCCESS`, `FAIL` or `ALL` -* `filters` array of transactions types +* `transactionsTypes` array of transactions types * `min` number of min `gas_used` * `max` number of max `gas_used` ``` -GET /transactions?=1&limit=10&order=asc&owner=6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs&filters=0&filters=1&status=ALL&min=0&max=9999999 +GET /transactions?=1&limit=10&order=asc&owner=6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs&transactionsTypes=0&transactionsTypes=1&status=ALL&min=0&max=9999999 { pagination: { diff --git a/packages/api/src/controllers/TransactionsController.js b/packages/api/src/controllers/TransactionsController.js index 225e9fef..1e15de81 100644 --- a/packages/api/src/controllers/TransactionsController.js +++ b/packages/api/src/controllers/TransactionsController.js @@ -2,7 +2,6 @@ const TransactionsDAO = require('../dao/TransactionsDAO') const utils = require('../utils') const { calculateInterval, iso8601duration } = require('../utils') const Intervals = require('../enums/IntervalsEnum') -const StateTransitionEnum = require('../enums/StateTransitionEnum') class TransactionsController { constructor (client, knex, dapi) { @@ -28,7 +27,7 @@ class TransactionsController { page = 1, limit = 10, order = 'asc', - filters, + transactionsTypes, owner, status = 'ALL', min, @@ -39,11 +38,7 @@ class TransactionsController { return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` }) } - const stateTransitionIndexes = Object.entries(StateTransitionEnum).map(([, entry]) => entry) - - const validatedFilters = filters?.map((filter) => stateTransitionIndexes.includes(filter)) - - if (validatedFilters?.includes(false) || filters?.length === 0) { + if (transactionsTypes?.length === 0 && transactionsTypes) { return response.status(400).send({ message: 'invalid filters values' }) } @@ -51,7 +46,7 @@ class TransactionsController { Number(page ?? 1), Number(limit ?? 10), order, - filters, + transactionsTypes, owner, status, min, diff --git a/packages/api/src/dao/TransactionsDAO.js b/packages/api/src/dao/TransactionsDAO.js index 30b617e7..ec7cbd93 100644 --- a/packages/api/src/dao/TransactionsDAO.js +++ b/packages/api/src/dao/TransactionsDAO.js @@ -49,17 +49,17 @@ module.exports = class TransactionsDAO { return Transaction.fromRow({ ...row, aliases }) } - getTransactions = async (page, limit, order, filters, owner, status, min, max) => { + getTransactions = async (page, limit, order, transactionsTypes, owner, status, min, max) => { const fromRank = ((page - 1) * limit) + 1 const toRank = fromRank + limit - 1 let filtersQuery = '' const filtersBindings = [] - if (filters) { + if (transactionsTypes) { // Currently knex cannot digest an array of numbers correctly // https://github.com/knex/knex/issues/2060 - filtersQuery = filters.length > 1 ? `type in (${filters.join(',')})` : `type = ${filters[0]}` + filtersQuery = transactionsTypes.length > 1 ? `type in (${transactionsTypes.join(',')})` : `type = ${transactionsTypes[0]}` } if (owner) { diff --git a/packages/api/src/schemas.js b/packages/api/src/schemas.js index 8752c100..e10cf2b7 100644 --- a/packages/api/src/schemas.js +++ b/packages/api/src/schemas.js @@ -32,10 +32,12 @@ const schemaTypes = [ minimum: 0, maximum: 8 }, - filters: { + transactionsTypes: { type: ['array', 'null'], items: { - type: 'number' + type: 'number', + minimum: 0, + maximum: 8 } }, status: { diff --git a/packages/api/test/integration/transactions.spec.js b/packages/api/test/integration/transactions.spec.js index c73e9720..e11875e1 100644 --- a/packages/api/test/integration/transactions.spec.js +++ b/packages/api/test/integration/transactions.spec.js @@ -277,7 +277,7 @@ describe('Transaction routes', () => { it('should return default set of transactions desc with owner and type filter', async () => { const owner = transactions[0].transaction.owner - const { body } = await client.get(`/transactions?order=desc&owner=${owner}&filters=0&filters=8`) + const { body } = await client.get(`/transactions?order=desc&owner=${owner}&transactionsTypes=0&transactionsTypes=8`) .expect(200) .expect('Content-Type', 'application/json; charset=utf-8') @@ -316,7 +316,7 @@ describe('Transaction routes', () => { it('should return default set of transactions desc with owner and type filter and status', async () => { const owner = transactions[0].transaction.owner - const { body } = await client.get(`/transactions?order=desc&owner=${owner}&filters=1&status=FAIL`) + const { body } = await client.get(`/transactions?order=desc&owner=${owner}&transactionsTypes=1&status=FAIL`) .expect(200) .expect('Content-Type', 'application/json; charset=utf-8') @@ -353,7 +353,7 @@ describe('Transaction routes', () => { it('should return default set of transactions desc with owner and type filter and min-max', async () => { const owner = transactions[0].transaction.owner - const { body } = await client.get(`/transactions?order=desc&owner=${owner}&filters=0&min=246&max=1107`) + const { body } = await client.get(`/transactions?order=desc&owner=${owner}&transactionsTypes=0&min=246&max=1107`) .expect(200) .expect('Content-Type', 'application/json; charset=utf-8') @@ -390,7 +390,7 @@ describe('Transaction routes', () => { it('should return empty set of transactions desc with owner and type filter', async () => { const owner = transactions[0].transaction.owner - const { body } = await client.get(`/transactions?order=desc&owner=${owner}&filters=8`) + const { body } = await client.get(`/transactions?order=desc&owner=${owner}&transactionsTypes=7`) .expect(200) .expect('Content-Type', 'application/json; charset=utf-8') diff --git a/packages/frontend/src/app/api/content.md b/packages/frontend/src/app/api/content.md index b0c60b5c..2f3725c7 100644 --- a/packages/frontend/src/app/api/content.md +++ b/packages/frontend/src/app/api/content.md @@ -430,12 +430,12 @@ Status can be either `SUCCESS` or `FAIL`. In case of error tx, message will appe * `limit` cannot be more then 100 * `owner` Identity identifier * `status` can be `SUCCESS`, `FAIL` or `ALL` -* `filters` array of transactions types +* `transactionsTypes` array of transactions types * `min` number of min `gas_used` * `max` number of max `gas_used` ``` -GET /transactions?=1&limit=10&order=asc&owner=6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs&filters=0&filters=1&status=ALL&min=0&max=9999999 +GET /transactions?=1&limit=10&order=asc&owner=6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs&transactionsTypes=0&transactionsTypes=1&status=ALL&min=0&max=9999999 { pagination: {