Skip to content

Commit

Permalink
all param replaced by zero limit (or null)
Browse files Browse the repository at this point in the history
  • Loading branch information
owl352 committed Sep 20, 2024
1 parent 471c7f9 commit 10d488a
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 293 deletions.
3 changes: 1 addition & 2 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ GET /blocks
Return all validators with pagination info.
* `lastProposedBlockHeader` field is nullable
* `?isActive=true` boolean can be supplied in the query params to filter by isActive field
* `limit` cannot be more then 100
* `all` boolean can be supplied in the query params to get all validators by params
* `limit` cannot be more then 100 (0 = all validators)
```
GET /validators
Expand Down
5 changes: 2 additions & 3 deletions packages/api/src/controllers/ValidatorsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ValidatorsController {
}

getValidators = async (request, response) => {
const { page = 1, limit = 10, order = 'asc', isActive = undefined, all = false } = request.query
const { page = 1, limit = 0, order = 'asc', isActive = undefined } = request.query

const activeValidators = await TenderdashRPC.getValidators()

Expand All @@ -45,8 +45,7 @@ class ValidatorsController {
Number(limit),
order,
isActive,
activeValidators,
all
activeValidators
)

const validatorsWithInfo = await Promise.all(
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/dao/ValidatorsDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ module.exports = class ValidatorsDAO {
return Validator.fromRow(row)
}

getValidators = async (page, limit, order, isActive, validators, all) => {
getValidators = async (page, limit, order, isActive, validators) => {
const fromRank = ((page - 1) * limit) + 1
const toRank = all ? this.knex.raw("'+infinity'::numeric") : fromRank + limit - 1
const toRank = limit ? fromRank + limit - 1 : this.knex.raw("'+infinity'::numeric")

const validatorsSubquery = this.knex('validators')
.select(
Expand Down Expand Up @@ -137,7 +137,7 @@ module.exports = class ValidatorsDAO {

const resultSet = rows.map((row) => Validator.fromRow(row))

return new PaginatedResultSet(resultSet, page, all ? resultSet.length : limit, totalCount)
return new PaginatedResultSet(resultSet, page, limit ?? resultSet.length, totalCount)
}

getValidatorStatsByProTxHash = async (proTxHash, timespan) => {
Expand Down
4 changes: 0 additions & 4 deletions packages/api/src/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const schemaTypes = [
minimum: 1,
maximum: 100
},
all: {
type: ['boolean', 'null'],
default: false
},
order: {
type: ['string', 'null'],
enum: ['asc', 'desc']
Expand Down
Loading

0 comments on commit 10d488a

Please sign in to comment.