From f56346e07a55e6f25d416e948c06e93d97b2b164 Mon Sep 17 00:00:00 2001 From: Aydar Farrakhov Date: Thu, 21 Mar 2024 12:47:13 +0300 Subject: [PATCH] add nfts in collection --- .../model/nfts-in-collection.model.ts | 4 ++-- .../resolvers/nfts-in-collection.resolver.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/indexer/src/server-extension/model/nfts-in-collection.model.ts b/indexer/src/server-extension/model/nfts-in-collection.model.ts index 65bd71e..34dd5b5 100644 --- a/indexer/src/server-extension/model/nfts-in-collection.model.ts +++ b/indexer/src/server-extension/model/nfts-in-collection.model.ts @@ -9,6 +9,6 @@ export class NftsInCollection { @Field(() => String) collection!: string; - @Field(() => String) - count!: string; + @Field(() => Number) + count!: number; } diff --git a/indexer/src/server-extension/resolvers/nfts-in-collection.resolver.ts b/indexer/src/server-extension/resolvers/nfts-in-collection.resolver.ts index c7afd41..de3d4f8 100644 --- a/indexer/src/server-extension/resolvers/nfts-in-collection.resolver.ts +++ b/indexer/src/server-extension/resolvers/nfts-in-collection.resolver.ts @@ -23,6 +23,17 @@ export class NftsInCollectionResolver { .select('count(nft.id) as count, collection_id as collection') .where('collection_id in (:...collections)', { collections }) .groupBy('collection_id'); - return query.getRawMany(); + const result = await query.getRawMany<{ + count: number; + collection: string; + }>(); + const collectionMap = result.reduce((acc, { collection, count }) => { + acc[collection] = count; + return acc; + }, {} as Record); + return collections.map((collection) => ({ + collection, + count: collectionMap[collection] || 0, + })); } }