Skip to content

Commit

Permalink
Showing 6 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
@@ -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: {
11 changes: 3 additions & 8 deletions packages/api/src/controllers/TransactionsController.js
Original file line number Diff line number Diff line change
@@ -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,19 +38,15 @@ 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' })
}

const transactions = await this.transactionsDAO.getTransactions(
Number(page ?? 1),
Number(limit ?? 10),
order,
filters,
transactionsTypes,
owner,
status,
min,
6 changes: 3 additions & 3 deletions packages/api/src/dao/TransactionsDAO.js
Original file line number Diff line number Diff line change
@@ -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) {
6 changes: 4 additions & 2 deletions packages/api/src/schemas.js
Original file line number Diff line number Diff line change
@@ -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: {
8 changes: 4 additions & 4 deletions packages/api/test/integration/transactions.spec.js
Original file line number Diff line number Diff line change
@@ -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')

4 changes: 2 additions & 2 deletions packages/frontend/src/app/api/content.md
Original file line number Diff line number Diff line change
@@ -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: {

0 comments on commit 3438390

Please sign in to comment.