Skip to content

Commit

Permalink
add nfts in collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ElessarST committed Mar 21, 2024
1 parent aa5ac0f commit f56346e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export class NftsInCollection {
@Field(() => String)
collection!: string;

@Field(() => String)
count!: string;
@Field(() => Number)
count!: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number>);
return collections.map((collection) => ({
collection,
count: collectionMap[collection] || 0,
}));
}
}

0 comments on commit f56346e

Please sign in to comment.