Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search term on assets #1023

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ input AssetsFilter {
identifiers: [String!]
likedByAddress: String
ownerAddress: String
searchTerm: String
tags: [String!]
traits: [NftTrait]
type: NftTypeEnum
Expand Down
4 changes: 3 additions & 1 deletion src/modules/assets/assets-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
) {}

async getAssetsForUser(address: string, query: string = '', countQuery: string = ''): Promise<CollectionType<Asset>> {
query = new AssetsQuery(query).addQuery('includeFlagged=true&source=elastic').build();
query = new AssetsQuery(query).addQuery('includeFlagged=true').build();

Check warning on line 45 in src/modules/assets/assets-getter.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/assets/assets-getter.service.ts#L45

Added line #L45 was not covered by tests
countQuery = new AssetsQuery(countQuery).addQuery('includeFlagged=true').build();
const [nfts, count] = await Promise.all([
this.apiService.getNftsForUser(address, query),
Expand Down Expand Up @@ -273,6 +273,7 @@
.addCollection(filters?.collection)
.addCollections(filters?.collections)
.addType(filters?.type)
.addSearchTerm(filters?.searchTerm)
.withOwner()
.withSupply()
.addPageSize(offset, limit)
Expand All @@ -287,6 +288,7 @@
.addCollection(filters?.collection)
.addCollections(filters?.collections)
.addType(filters?.type)
.addSearchTerm(filters?.searchTerm)
.withSupply()
.addPageSize(offset, limit)
.build();
Expand Down
8 changes: 7 additions & 1 deletion src/modules/common/filters/filtersTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, InputType, registerEnumType } from '@nestjs/graphql';
import { IsOptional, Matches } from 'class-validator';
import { IsOptional, Matches, MinLength } from 'class-validator';
import { NftTrait } from 'src/modules/nft-traits/models/nft-traits.model';
import {
ADDRESS_ERROR,
Expand Down Expand Up @@ -185,6 +185,12 @@ export class AssetsFilter {
@Field(() => [NftTrait], { nullable: 'itemsAndList' })
traits: NftTrait[];

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

constructor(init?: Partial<AssetsFilter>) {
Object.assign(this, init);
}
Expand Down