Skip to content

Commit

Permalink
Merge pull request #1031 from multiversx/SERVICES-1856-fix-assets-que…
Browse files Browse the repository at this point in the history
…ry-filter-by-collections

Services 1856 fix assets query filter by collections
  • Loading branch information
danielailie authored Sep 26, 2023
2 parents f3266c1 + 7c83076 commit 8aec7de
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ input CollectionsFilter {

"""The owner of the collection"""
ownerAddress: String
searchTerm: String
type: NftTypeEnum

"""Flag for verified collections"""
Expand Down
16 changes: 12 additions & 4 deletions src/modules/artists/smart-contract-artist.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ export class SmartContractArtistsService {
}

public async getArtistForScAddress(scAddress: string): Promise<{ address: string; owner: string }> {
const account = await this.mxApiService.getSmartContractOwner(scAddress);
if (account.owner === XOXNO_MINTING_MANAGER) {
return await this.getXoxnoMinterOwner(scAddress);
try {
const account = await this.mxApiService.getSmartContractOwner(scAddress);
if (account.owner === XOXNO_MINTING_MANAGER) {
return await this.getXoxnoMinterOwner(scAddress);
}
return account;
} catch (error) {
this.logger.error('There was an error while getting the smartcontract owner', scAddress, error);
return {
address: scAddress,
owner: scAddress,
};
}
return account;
}

private async getXoxnoMinterOwner(scAddress: string): Promise<{ address: string; owner: string }> {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/assets/assets-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class AssetsGetterService {
const ticketCollectionIdentifiers = ticketsCollections.map((x) => x.collection).toString();
return await this.getAssetsForUser(
filters.ownerAddress,
`?collections=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`,
`?collections=${ticketCollectionIdentifiers}`,
`?identifiers=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`,
`?identifiers=${ticketCollectionIdentifiers}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/assets/assets-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AssetsQuery {
}

addCollections(collections: string[]): this {
return this.addParamToQuery('collections', collections?.toString());
return this.addParamToQuery('identifiers', collections?.toString());
}

addType(type: NftTypeEnum): this {
Expand Down
7 changes: 7 additions & 0 deletions src/modules/nftCollections/collection-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export class CollectionQuery {
return this;
}

addSearchTerm(searchTerm: string): this {
if (searchTerm === undefined) return this;
if (this.query === '') this.query = `?search=${encodeURIComponent(searchTerm)}`;
else this.query = `${this.query}&search=${encodeURIComponent(searchTerm)}`;
return this;
}

addPageSize(from: number, size: number): this {
if ((!from && from < 0) || !size) {
return this;
Expand Down
11 changes: 11 additions & 0 deletions src/modules/nftCollections/collections-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ export class CollectionsGetterService {
if (filters?.type) {
collections = collections?.filter((token) => token.type === filters?.type);
}
if (filters?.searchTerm) {
collections = collections.filter(
(x) =>
x.verified &&
(x.name?.toLowerCase()?.includes(filters.searchTerm.toLowerCase()) ||
x.collection?.toLowerCase()?.includes(filters.searchTerm.toLowerCase())),
);
collections = collections?.filter((token) => token.type === filters?.type);
}

return collections;
}

Expand Down Expand Up @@ -360,6 +370,7 @@ export class CollectionsGetterService {
.addCreator(filters?.creatorAddress)
.addType(filters?.type)
.addCanCreate(filters?.canCreate)
.addSearchTerm(filters?.searchTerm)
.addPageSize(offset, limit)
.build();
if (filters?.collection) {
Expand Down
9 changes: 8 additions & 1 deletion src/modules/nftCollections/models/Collections-Filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InputType, Field, registerEnumType } from '@nestjs/graphql';
import { IsOptional, Matches } from 'class-validator';
import { IsOptional, Matches, MinLength } from 'class-validator';
import { NftTypeEnum } from 'src/modules/assets/models';
import { ADDRESS_RGX, ADDRESS_ERROR, COLLECTION_IDENTIFIER_RGX, COLLECTION_IDENTIFIER_ERROR } from 'src/utils/constants';

Expand Down Expand Up @@ -63,6 +63,13 @@ export class CollectionsFilter {
description: 'Flag for active last 30 days',
})
activeLast30Days: boolean;

@IsOptional()
@Field(() => String, { nullable: true })
@MinLength(3, {
message: 'The search term should contain at least 3 characters',
})
searchTerm: string;
}
@InputType()
export class AssetsCollectionFilter {
Expand Down

0 comments on commit 8aec7de

Please sign in to comment.