Skip to content

Commit

Permalink
add parse enum pipe for collection and nft endpoints (#659)
Browse files Browse the repository at this point in the history
* add parse enum pipe for collection and nft endpoints

* revert optionalEnumPipe from getNfts()

* remove type filter for :collection/nfts/count and :collection/nfts

* add dropdown options into swagger

* update status ApiQuery param with enum: TransactionStatus

* update sort ApiQuery param with enum: SortNodes

* update boolean fields

* updated endpoint descriptions

Co-authored-by: Traian Anghel <[email protected]>
  • Loading branch information
cfaur09 and tanghel authored Jun 6, 2022
1 parent 08e7d46 commit 9ff3f4d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 44 deletions.
11 changes: 11 additions & 0 deletions src/common/entities/sort.nodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum SortNodes {
name = 'name',
version = 'version',
tempRating = 'tempRating',
leaderSuccess = 'leaderSuccess',
leaderFailure = 'leaderFailure',
validatorSuccess = 'validatorSuccess',
validatorFailure = 'validatorFailure',
validatorIgnoredSignatures = 'validatorIgnoredSignatures',
position = 'position',
}
6 changes: 6 additions & 0 deletions src/common/entities/sort.tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum SortTokens {
accounts = 'accounts',
transactions = 'transactions',
price = 'price',
marketCap = 'marketCap',
}
14 changes: 7 additions & 7 deletions src/endpoints/accounts/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class AccountController {
}

@Get("/accounts/:address/transactions")
@ApiOperation({ summary: 'Account transactions details', description: 'Returns details of all transactions where the account is sender or receiver' })
@ApiOperation({ summary: 'Account transaction list', description: 'Returns details of all transactions where the account is sender or receiver' })
@ApiOkResponse({ type: [Transaction] })
@ApiQuery({ name: 'from', description: 'Number of items to skip for the result set', required: false })
@ApiQuery({ name: 'size', description: 'Number of items to retrieve', required: false })
Expand All @@ -524,9 +524,9 @@ export class AccountController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transaction hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false, enum: SortOrder })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
@ApiQuery({ name: 'withScResults', description: 'Return scResults for transactions', required: false })
Expand Down Expand Up @@ -588,7 +588,7 @@ export class AccountController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transaction hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'function', description: 'Filter transactions by function name', required: false })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
Expand Down Expand Up @@ -637,9 +637,9 @@ export class AccountController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transfer hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transfer (success / pending / invalid)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false, enum: SortOrder })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
async getAccountTransfers(
Expand Down Expand Up @@ -689,7 +689,7 @@ export class AccountController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transfer hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transfer (success / pending / invalid)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'function', description: 'Filter transfers by function name', required: false })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
Expand Down
20 changes: 8 additions & 12 deletions src/endpoints/collections/collection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,19 @@ export class CollectionController {
@ApiQuery({ name: 'size', description: 'Number of items to retrieve', required: false })
@ApiQuery({ name: 'search', description: 'Search by collection identifier', required: false })
@ApiQuery({ name: 'identifiers', description: 'Search by token identifiers, comma-separated', required: false })
@ApiQuery({ name: 'type', description: 'Filter by type (NonFungibleESDT/SemiFungibleESDT/MetaESDT)', required: false })
@ApiQuery({ name: 'name', description: 'Get all nfts by name', required: false })
@ApiQuery({ name: 'tags', description: 'Filter by one or more comma-separated tags', required: false })
@ApiQuery({ name: 'creator', description: 'Return all NFTs associated with a given creator', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false })
@ApiQuery({ name: 'withOwner', description: 'Return owner where type = NonFungibleESDT', required: false })
@ApiQuery({ name: 'withSupply', description: 'Return supply where type = SemiFungibleESDT', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false, type: Boolean })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false, type: Boolean })
@ApiQuery({ name: 'withOwner', description: 'Return owner where type = NonFungibleESDT', required: false, type: Boolean })
@ApiQuery({ name: 'withSupply', description: 'Return supply where type = SemiFungibleESDT', required: false, type: Boolean })
async getNfts(
@Param('collection') collection: string,
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search: string | undefined,
@Query('identifiers', ParseArrayPipe) identifiers: string[] | undefined,
@Query('type') type: NftType | undefined,
@Query('name') name: string | undefined,
@Query('tags', ParseArrayPipe) tags: string[] | undefined,
@Query('creator', ParseAddressPipe) creator: string | undefined,
Expand All @@ -168,31 +166,29 @@ export class CollectionController {
throw new BadRequestException(`Maximum size of 100 is allowed when activating flags 'withOwner' or 'withSupply'`);
}

return await this.nftService.getNfts({ from, size }, { search, identifiers, type, collection, name, tags, creator, hasUris, isWhitelistedStorage }, { withOwner, withSupply });
return await this.nftService.getNfts({ from, size }, { search, identifiers, collection, name, tags, creator, hasUris, isWhitelistedStorage }, { withOwner, withSupply });
}

@Get("/collections/:collection/nfts/count")
@ApiOperation({ summary: 'Collection NFT count', description: 'Returns non-fungible/semi-fungible/meta-esdt token count that belong to a collection' })
@ApiOkResponse({ type: Number })
@ApiQuery({ name: 'search', description: 'Search by collection identifier', required: false })
@ApiQuery({ name: 'identifiers', description: 'Search by token identifiers, comma-separated', required: false })
@ApiQuery({ name: 'type', description: 'Filter by type (NonFungibleESDT/SemiFungibleESDT/MetaESDT)', required: false })
@ApiQuery({ name: 'name', description: 'Get all nfts by name', required: false })
@ApiQuery({ name: 'tags', description: 'Filter by one or more comma-separated tags', required: false })
@ApiQuery({ name: 'creator', description: 'Return all NFTs associated with a given creator', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false, type: Boolean })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false, type: Boolean })
async getNftCount(
@Param('collection') collection: string,
@Query('search') search: string | undefined,
@Query('identifiers', ParseArrayPipe) identifiers: string[] | undefined,
@Query('type') type: NftType | undefined,
@Query('name') name: string | undefined,
@Query('tags', ParseArrayPipe) tags: string[] | undefined,
@Query('creator', ParseAddressPipe) creator: string | undefined,
@Query('isWhitelistedStorage', new ParseOptionalBoolPipe) isWhitelistedStorage: boolean | undefined,
@Query('hasUris', new ParseOptionalBoolPipe) hasUris: boolean | undefined,
): Promise<number> {
return await this.nftService.getNftCount({ search, identifiers, type, collection, name, tags, creator, isWhitelistedStorage, hasUris });
return await this.nftService.getNftCount({ search, identifiers, collection, name, tags, creator, isWhitelistedStorage, hasUris });
}
}
12 changes: 6 additions & 6 deletions src/endpoints/nfts/nft.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class NftController {
@ApiQuery({ name: 'name', description: 'Get all nfts by name', required: false })
@ApiQuery({ name: 'tags', description: 'Filter by one or more comma-separated tags', required: false })
@ApiQuery({ name: 'creator', description: 'Return all NFTs associated with a given creator', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false })
@ApiQuery({ name: 'withOwner', description: 'Return owner where type = NonFungibleESDT', required: false })
@ApiQuery({ name: 'withSupply', description: 'Return supply where type = SemiFungibleESDT', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false, type: Boolean })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false, type: Boolean })
@ApiQuery({ name: 'withOwner', description: 'Return owner where type = NonFungibleESDT', required: false, type: Boolean })
@ApiQuery({ name: 'withSupply', description: 'Return supply where type = SemiFungibleESDT', required: false, type: Boolean })
async getNfts(
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
Expand Down Expand Up @@ -67,8 +67,8 @@ export class NftController {
@ApiQuery({ name: 'name', description: 'Get all nfts by name', required: false })
@ApiQuery({ name: 'tags', description: 'Filter by one or more comma-separated tags', required: false })
@ApiQuery({ name: 'creator', description: 'Return all NFTs associated with a given creator', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false })
@ApiQuery({ name: 'isWhitelistedStorage', description: 'Return all NFTs that are whitelisted in storage', required: false, type: Boolean })
@ApiQuery({ name: 'hasUris', description: 'Return all NFTs that have one or more uris', required: false, type: Boolean })
async getNftCount(
@Query('search') search: string | undefined,
@Query('identifiers', ParseArrayPipe) identifiers: string[] | undefined,
Expand Down
9 changes: 5 additions & 4 deletions src/endpoints/nodes/node.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SortOrder } from "src/common/entities/sort.order";
import { NodeSort } from "./entities/node.sort";
import { ParseAddressPipe } from "src/utils/pipes/parse.address.pipe";
import { ParseBlsHashPipe } from "src/utils/pipes/parse.bls.hash.pipe";
import { SortNodes } from "src/common/entities/sort.nodes";

@Controller()
@ApiTags('nodes')
Expand All @@ -31,8 +32,8 @@ export class NodeController {
@ApiQuery({ name: 'identity', description: 'Node identity', required: false })
@ApiQuery({ name: 'provider', description: 'Node provider', required: false })
@ApiQuery({ name: 'owner', description: 'Node owner', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false, enum: SortNodes })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false, enum: SortOrder })
async getNodes(
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
Expand Down Expand Up @@ -70,8 +71,8 @@ export class NodeController {
@ApiQuery({ name: 'identity', description: 'Node identity', required: false })
@ApiQuery({ name: 'provider', description: 'Node provider', required: false })
@ApiQuery({ name: 'owner', description: 'Node owner', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false, enum: SortNodes })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false, enum: SortOrder })
getNodeCount(
@Query('search') search: string | undefined,
@Query('online', ParseOptionalBoolPipe) online: boolean | undefined,
Expand Down
17 changes: 9 additions & 8 deletions src/endpoints/tokens/token.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { EsdtSupply } from "../esdt/entities/esdt.supply";
import { Transaction } from "../transactions/entities/transaction";
import { TokenSupplyResult } from "./entities/token.supply.result";
import { TokenSort } from "./entities/token.sort";
import { SortTokens } from "src/common/entities/sort.tokens";


@Controller()
Expand All @@ -36,8 +37,8 @@ export class TokenController {
@ApiQuery({ name: 'name', description: 'Search by token name', required: false })
@ApiQuery({ name: 'identifier', description: 'Search by token identifier', required: false })
@ApiQuery({ name: 'identifiers', description: 'Search by multiple token identifiers, comma-separated', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false })
@ApiQuery({ name: 'sort', description: 'Sorting criteria', required: false, enum: SortTokens })
@ApiQuery({ name: 'order', description: 'Sorting order (asc / desc)', required: false, enum: SortOrder })
async getTokens(
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
Expand Down Expand Up @@ -167,17 +168,17 @@ export class TokenController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transaction hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / fail)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'function', description: 'Filter transactions by function name', required: false })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false })
@ApiQuery({ name: 'order', description: 'Sort order (asc/desc)', required: false, enum: SortOrder })
@ApiQuery({ name: 'from', description: 'Number of items to skip for the result set', required: false })
@ApiQuery({ name: 'size', description: 'Number of items to retrieve', required: false })
@ApiQuery({ name: 'withScResults', description: 'Return scResults for transactions', required: false })
@ApiQuery({ name: 'withOperations', description: 'Return operations for transactions', required: false })
@ApiQuery({ name: 'withLogs', description: 'Return logs for transactions', required: false })
@ApiQuery({ name: 'withScResults', description: 'Return scResults for transactions', required: false, type: Boolean })
@ApiQuery({ name: 'withOperations', description: 'Return operations for transactions', required: false, type: Boolean })
@ApiQuery({ name: 'withLogs', description: 'Return logs for transactions', required: false, type: Boolean })
async getTokenTransactions(
@Param('identifier') identifier: string,
@Query('sender', ParseAddressPipe) sender: string | undefined,
Expand Down Expand Up @@ -234,7 +235,7 @@ export class TokenController {
@ApiQuery({ name: 'receiverShard', description: 'Id of the shard the receiver address belongs to', required: false })
@ApiQuery({ name: 'miniBlockHash', description: 'Filter by miniblock hash', required: false })
@ApiQuery({ name: 'hashes', description: 'Filter by a comma-separated list of transaction hashes', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid)', required: false })
@ApiQuery({ name: 'status', description: 'Status of the transaction (success / pending / invalid / fail)', required: false, enum: TransactionStatus })
@ApiQuery({ name: 'search', description: 'Search in data object', required: false })
@ApiQuery({ name: 'before', description: 'Before timestamp', required: false })
@ApiQuery({ name: 'after', description: 'After timestamp', required: false })
Expand Down
1 change: 1 addition & 0 deletions src/endpoints/transactions/entities/transaction.status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum TransactionStatus {
success = 'success',
pending = 'pending',
invalid = 'invalid',
fail = 'fail'
}
Loading

0 comments on commit 9ff3f4d

Please sign in to comment.