Skip to content

Commit

Permalink
add support for identifiers validation pipe (#1132)
Browse files Browse the repository at this point in the history
* add nfts identifiers validation

* add ParseCollectionArrayPipe

* add collections filter into /nfts
  • Loading branch information
cfaur09 authored Oct 26, 2023
1 parent b49d38b commit cbdb4c0
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 55 deletions.
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@
"@elrondnetwork/transaction-processor": "^0.1.26",
"@golevelup/nestjs-rabbitmq": "^2.2.0",
"@multiversx/sdk-data-api-client": "^0.4.4",
"@multiversx/sdk-nestjs-auth": "^1.2.7",
"@multiversx/sdk-nestjs-cache": "^1.2.7",
"@multiversx/sdk-nestjs-common": "^1.2.7",
"@multiversx/sdk-nestjs-elastic": "^1.2.7",
"@multiversx/sdk-nestjs-http": "^1.2.7",
"@multiversx/sdk-nestjs-monitoring": "^1.2.7",
"@multiversx/sdk-nestjs-rabbitmq": "^1.2.7",
"@multiversx/sdk-nestjs-redis": "^1.2.7",
"@multiversx/sdk-nestjs-auth": "^1.2.8",
"@multiversx/sdk-nestjs-cache": "^1.2.8",
"@multiversx/sdk-nestjs-common": "^1.2.8",
"@multiversx/sdk-nestjs-elastic": "^1.2.8",
"@multiversx/sdk-nestjs-http": "^1.2.8",
"@multiversx/sdk-nestjs-monitoring": "^1.2.8",
"@multiversx/sdk-nestjs-rabbitmq": "^1.2.8",
"@multiversx/sdk-nestjs-redis": "^1.2.8",
"@multiversx/sdk-wallet": "^4.0.0",
"@nestjs/apollo": "^10.1.3",
"@nestjs/common": "^9.1.4",
Expand Down
8 changes: 4 additions & 4 deletions src/endpoints/accounts/account.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { ProviderStake } from '../stake/entities/provider.stake';
import { TokenDetailedWithBalance } from '../tokens/entities/token.detailed.with.balance';
import { NftCollectionAccount } from '../collections/entities/nft.collection.account';
import { TokenWithRoles } from '../tokens/entities/token.with.roles';
import { ParseAddressPipe, ParseTokenPipe, OriginLogger, ParseArrayPipe, ParseBlockHashPipe, ParseCollectionPipe, ParseNftPipe, ParseBoolPipe, ParseEnumArrayPipe, ParseEnumPipe, ParseIntPipe, ParseTokenOrNftPipe, ParseTransactionHashPipe, ParseAddressArrayPipe, ApplyComplexity } from '@multiversx/sdk-nestjs-common';
import { ParseAddressPipe, ParseTokenPipe, OriginLogger, ParseArrayPipe, ParseBlockHashPipe, ParseCollectionPipe, ParseNftPipe, ParseBoolPipe, ParseEnumArrayPipe, ParseEnumPipe, ParseIntPipe, ParseTokenOrNftPipe, ParseTransactionHashPipe, ParseAddressArrayPipe, ApplyComplexity, ParseNftArrayPipe } from '@multiversx/sdk-nestjs-common';
import { QueryPagination } from 'src/common/entities/query.pagination';
import { TransactionQueryOptions } from '../transactions/entities/transactions.query.options';
import { TokenWithRolesFilter } from '../tokens/entities/token.with.roles.filter';
Expand Down Expand Up @@ -496,7 +496,7 @@ export class AccountController {
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('collection') collection?: string,
@Query('collections', ParseArrayPipe) collections?: string[],
Expand Down Expand Up @@ -540,7 +540,7 @@ export class AccountController {
@ApiOkResponse({ type: Number })
async getNftCount(
@Param('address', ParseAddressPipe) address: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('search') search?: string,
@Query('type') type?: NftType,
@Query('collection') collection?: string,
Expand All @@ -560,7 +560,7 @@ export class AccountController {
async getNftCountAlternative(
@Param('address', ParseAddressPipe) address: string,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('collection') collection?: string,
@Query('collections', ParseArrayPipe) collections?: string[],
Expand Down
8 changes: 4 additions & 4 deletions src/endpoints/collections/collection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Nft } from "../nfts/entities/nft";
import { NftService } from "../nfts/nft.service";
import { NftFilter } from "../nfts/entities/nft.filter";
import { NftQueryOptions } from "../nfts/entities/nft.query.options";
import { ParseAddressPipe, ParseArrayPipe, ParseCollectionPipe, ParseBoolPipe, ParseEnumArrayPipe, ParseIntPipe, ApplyComplexity, ParseAddressArrayPipe, ParseBlockHashPipe, ParseEnumPipe, ParseRecordPipe } from '@multiversx/sdk-nestjs-common';
import { ParseAddressPipe, ParseArrayPipe, ParseCollectionPipe, ParseBoolPipe, ParseEnumArrayPipe, ParseIntPipe, ApplyComplexity, ParseAddressArrayPipe, ParseBlockHashPipe, ParseEnumPipe, ParseRecordPipe, ParseNftArrayPipe, ParseCollectionArrayPipe } from '@multiversx/sdk-nestjs-common';
import { QueryPagination } from "src/common/entities/query.pagination";
import { CollectionFilter } from "./entities/collection.filter";
import { CollectionAccount } from "./entities/collection.account";
Expand Down Expand Up @@ -58,7 +58,7 @@ export class CollectionController {
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseCollectionArrayPipe) identifiers?: string[],
@Query('type', new ParseEnumArrayPipe(NftType)) type?: NftType[],
@Query('creator', ParseAddressPipe) creator?: string,
@Query('before', new ParseIntPipe) before?: number,
Expand Down Expand Up @@ -225,7 +225,7 @@ export class CollectionController {
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('name') name?: string,
@Query('tags', ParseArrayPipe) tags?: string[],
@Query('creator', ParseAddressPipe) creator?: string,
Expand Down Expand Up @@ -273,7 +273,7 @@ export class CollectionController {
async getNftCount(
@Param('collection', ParseCollectionPipe) collection: string,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('name') name?: string,
@Query('tags', ParseArrayPipe) tags?: string[],
@Query('creator', ParseAddressPipe) creator?: string,
Expand Down
19 changes: 12 additions & 7 deletions src/endpoints/nfts/nft.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NftType } from "./entities/nft.type";
import { NftService } from "./nft.service";
import { QueryPagination } from 'src/common/entities/query.pagination';
import { NftQueryOptions } from './entities/nft.query.options';
import { ParseAddressPipe, ParseBoolPipe, ParseArrayPipe, ParseIntPipe, ParseNftPipe, ParseCollectionPipe, ApplyComplexity, ParseAddressArrayPipe, ParseBlockHashPipe, ParseEnumPipe, ParseRecordPipe } from '@multiversx/sdk-nestjs-common';
import { ParseAddressPipe, ParseBoolPipe, ParseArrayPipe, ParseIntPipe, ParseNftPipe, ParseCollectionPipe, ApplyComplexity, ParseAddressArrayPipe, ParseBlockHashPipe, ParseEnumPipe, ParseRecordPipe, ParseNftArrayPipe, ParseCollectionArrayPipe } from '@multiversx/sdk-nestjs-common';
import { TransactionDetailed } from '../transactions/entities/transaction.detailed';
import { TransactionStatus } from '../transactions/entities/transaction.status';
import { SortOrder } from 'src/common/entities/sort.order';
Expand Down Expand Up @@ -37,6 +37,7 @@ export class NftController {
@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: 'collection', description: 'Get all tokens by token collection', required: false })
@ApiQuery({ name: 'collections', description: 'Get all tokens by token collections, comma-separated', 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 })
Expand All @@ -54,9 +55,10 @@ export class NftController {
@Query('from', new DefaultValuePipe(0), ParseIntPipe) from: number,
@Query('size', new DefaultValuePipe(25), ParseIntPipe) size: number,
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('collection', ParseCollectionPipe) collection?: string,
@Query('collections', ParseCollectionArrayPipe) collections?: string[],
@Query('name') name?: string,
@Query('tags', ParseArrayPipe) tags?: string[],
@Query('creator', ParseAddressPipe) creator?: string,
Expand All @@ -75,7 +77,7 @@ export class NftController {

return await this.nftService.getNfts(
new QueryPagination({ from, size }),
new NftFilter({ search, identifiers, type, collection, name, tags, creator, hasUris, isWhitelistedStorage, isNsfw, traits, before, after }),
new NftFilter({ search, identifiers, type, collection, collections, name, tags, creator, hasUris, isWhitelistedStorage, isNsfw, traits, before, after }),
options
);
}
Expand All @@ -87,6 +89,7 @@ export class NftController {
@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: 'collection', description: 'Get all tokens by token collection', required: false })
@ApiQuery({ name: 'collections', description: 'Get all tokens by token collections, comma-separated', 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 })
Expand All @@ -98,9 +101,10 @@ export class NftController {
@ApiQuery({ name: 'after', description: 'Return all NFTs after given timestamp', required: false, type: Number })
async getNftCount(
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('collection', ParseCollectionPipe) collection?: string,
@Query('collections', ParseCollectionArrayPipe) collections?: string[],
@Query('name') name?: string,
@Query('tags', ParseArrayPipe) tags?: string[],
@Query('creator', ParseAddressPipe) creator?: string,
Expand All @@ -111,16 +115,17 @@ export class NftController {
@Query('before', new ParseIntPipe) before?: number,
@Query('after', new ParseIntPipe) after?: number,
): Promise<number> {
return await this.nftService.getNftCount(new NftFilter({ search, identifiers, type, collection, name, tags, creator, isWhitelistedStorage, hasUris, isNsfw, traits, before, after }));
return await this.nftService.getNftCount(new NftFilter({ search, identifiers, type, collection, collections, name, tags, creator, isWhitelistedStorage, hasUris, isNsfw, traits, before, after }));
}

@Get("/nfts/c")
@ApiExcludeEndpoint()
async getNftCountAlternative(
@Query('search') search?: string,
@Query('identifiers', ParseArrayPipe) identifiers?: string[],
@Query('identifiers', ParseNftArrayPipe) identifiers?: string[],
@Query('type') type?: NftType,
@Query('collection', ParseCollectionPipe) collection?: string,
@Query('collections', ParseCollectionArrayPipe) collections?: string[],
@Query('name') name?: string,
@Query('tags', ParseArrayPipe) tags?: string[],
@Query('creator', ParseAddressPipe) creator?: string,
Expand All @@ -131,7 +136,7 @@ export class NftController {
@Query('before', new ParseIntPipe) before?: number,
@Query('after', new ParseIntPipe) after?: number,
): Promise<number> {
return await this.nftService.getNftCount(new NftFilter({ search, identifiers, type, collection, name, tags, creator, isWhitelistedStorage, hasUris, isNsfw, traits, before, after }));
return await this.nftService.getNftCount(new NftFilter({ search, identifiers, type, collection, collections, name, tags, creator, isWhitelistedStorage, hasUris, isNsfw, traits, before, after }));
}

@Get('/nfts/:identifier')
Expand Down

0 comments on commit cbdb4c0

Please sign in to comment.