Skip to content

Commit

Permalink
Merge pull request #191 from UniqueNetwork/feature/show_tokens_owners
Browse files Browse the repository at this point in the history
Feature/show tokens owners
  • Loading branch information
icehuntmen committed Feb 2, 2023
2 parents e13f638 + eaa2a9d commit e0c1ee3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/web-api/src/tokens/token.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum TokenDistinctFieldsEnum {
owner_normalized = 'owner_normalized',
token_prefix = 'token_prefix',
collection_name = 'collection_name',
tokens_owner = 'tokens_owner',
token_name = 'token_name',
}

Expand Down Expand Up @@ -65,6 +66,9 @@ export class SimpleTokenDTO implements Partial<Tokens> {
@Field(() => String, { nullable: true })
total_pieces?: number;

@Field(() => String, { nullable: true })
amount?: number;

@Field(() => Boolean)
nested?: boolean;
}
Expand All @@ -74,6 +78,12 @@ export class TokenDTO extends SimpleTokenDTO implements Partial<Tokens> {
@Field(() => String)
collection_name?: string;

@Field(() => String, { nullable: true })
tokens_owner?: string;

@Field(() => String, { nullable: true })
tokens_amount?: string;

@Field(() => String, { nullable: true })
collection_description?: string;

Expand Down
19 changes: 19 additions & 0 deletions apps/web-api/src/tokens/token.resolver.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../utils/gql-query-args';
import { SimpleTokenDTO, TokenDistinctFieldsEnum, TokenDTO } from './token.dto';
import { CollectionDTO } from '../collection/collection.dto';
import { TokenOwnersDTO } from '../tokens-owners/token-owners.dto';

registerEnumType(TokenType, { name: 'TokenTypeEnum' });
registerEnumType(TokenDistinctFieldsEnum, { name: 'TokenEnum' });
Expand Down Expand Up @@ -62,6 +63,12 @@ export class TokenWhereParams implements TWhereParams<TokenDTO> {
@Field(() => GQLWhereOpsString, { nullable: true })
collection_name?: GQLWhereOpsString;

@Field(() => GQLWhereOpsString, { nullable: true })
tokens_owner?: GQLWhereOpsString;

@Field(() => GQLWhereOpsString, { nullable: true })
tokens_amount?: GQLWhereOpsString;

@Field(() => GQLWhereOpsString, { nullable: true })
collection_owner?: GQLWhereOpsString;

Expand Down Expand Up @@ -110,6 +117,12 @@ export class TokenOrderByParams implements TOrderByParams<TokenDTO> {
@Field(() => GQLOrderByParamsArgs, { nullable: true })
owner?: GQLOrderByParamsArgs;

@Field(() => GQLOrderByParamsArgs, { nullable: true })
tokens_owner?: GQLOrderByParamsArgs;

@Field(() => GQLOrderByParamsArgs, { nullable: true })
tokens_amount?: GQLOrderByParamsArgs;

@Field(() => GQLOrderByParamsArgs, { nullable: true })
owner_normalized?: GQLOrderByParamsArgs;

Expand Down Expand Up @@ -145,6 +158,9 @@ export class TokenOrderByParams implements TOrderByParams<TokenDTO> {

@Field(() => GQLOrderByParamsArgs, { nullable: true })
total_pieces?: GQLOrderByParamsArgs;

@Field(() => GQLOrderByParamsArgs, { nullable: true })
amount?: GQLOrderByParamsArgs;
}

@ArgsType()
Expand Down Expand Up @@ -178,6 +194,9 @@ export class NestingArgs {
export class TokenEntity extends TokenDTO {
@Field(() => CollectionDTO, { nullable: true })
collection?: CollectionDTO;

@Field(() => TokenOwnersDTO, { nullable: true })
tokensOwners?: TokenOwnersDTO;
}

@ObjectType()
Expand Down
12 changes: 12 additions & 0 deletions apps/web-api/src/tokens/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { GraphQLResolveInfo } from 'graphql';
import { IRelations } from '../utils/base.service.types';
import { FieldsListOptions } from 'graphql-fields-list';
import { JOIN_TYPE } from '@common/constants';
import { TokensOwners } from '@entities/TokensOwners';

const TOKENSOWNERS_RELATION_ALIAS = 'TokenOwners';
const COLLECTION_RELATION_ALIAS = 'Collection';
const STATISTICS_RELATION_ALIAS = 'Statistics';

Expand All @@ -27,6 +29,8 @@ const relationsFields = {
collection_owner_normalized: COLLECTION_RELATION_ALIAS,
collection_cover: COLLECTION_RELATION_ALIAS,
collection_description: COLLECTION_RELATION_ALIAS,
tokens_owner: TOKENSOWNERS_RELATION_ALIAS,
tokens_amount: TOKENSOWNERS_RELATION_ALIAS,

transfers_count: STATISTICS_RELATION_ALIAS,
children_count: STATISTICS_RELATION_ALIAS,
Expand All @@ -37,6 +41,8 @@ const aliasFields = {
collection_owner: 'owner',
collection_owner_normalized: 'owner_normalized',
collection_description: 'description',
tokens_owner: 'owner',
tokens_amount: 'amount',
};

const customQueryFields = {
Expand All @@ -58,6 +64,7 @@ export class TokenService extends BaseService<Tokens, TokenDTO> {
queryInfo: GraphQLResolveInfo,
): Promise<IDataListResponse<TokenDTO>> {
const qb = this.repo.createQueryBuilder();

this.applyArgs(qb, queryArgs, queryInfo);

return this.getDataAndCount(qb, queryArgs);
Expand Down Expand Up @@ -249,6 +256,11 @@ export class TokenService extends BaseService<Tokens, TokenDTO> {
on: `"Tokens".collection_id = "${COLLECTION_RELATION_ALIAS}".collection_id`,
join: JOIN_TYPE.INNER,
},
[TOKENSOWNERS_RELATION_ALIAS]: {
table: 'tokens_owners',
on: `"Tokens".collection_id = "${TOKENSOWNERS_RELATION_ALIAS}".collection_id AND "Tokens".token_id = "${TOKENSOWNERS_RELATION_ALIAS}".token_id`,
join: JOIN_TYPE.INNER,
},
[STATISTICS_RELATION_ALIAS]: {
table: 'tokens_stats',
on: `"Tokens".token_id = "${STATISTICS_RELATION_ALIAS}".token_id
Expand Down
15 changes: 15 additions & 0 deletions migrations/1675323128108-add-index-tokens-owners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class addindextokensowners1675323128108 implements MigrationInterface {
name = 'addindextokensowners1675323128108';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE INDEX "tokens_owners_general_idx" ON "tokens_owners" ("collection_id", "token_id", "owner") `,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."tokens_owners_general_idx"`);
}
}

0 comments on commit e0c1ee3

Please sign in to comment.