Quellcode durchsuchen

sold NFTs amount for topSellingChannels (#125)

* added sold nfts count
attemka vor 1 Jahr
Ursprung
Commit
344e2d90cf

+ 3 - 0
src/server-extension/resolvers/ChannelsResolver/types.ts

@@ -19,6 +19,9 @@ export class TopSellingChannelsResult {
 
   @Field(() => String, { nullable: false })
   amount!: string
+
+  @Field(() => Int, { nullable: false })
+  nftSold!: number
 }
 
 @ObjectType()

+ 14 - 3
src/server-extension/resolvers/ChannelsResolver/utils.ts

@@ -130,7 +130,11 @@ export function buildTopSellingChannelsQuery(
   let listQuerySql = listQuery.sql
 
   // Count NFT sells from the auctions and buy now events and add them to the query
-  listQuerySql = extendClause(listQuerySql, 'SELECT', '"top_selling_channels"."amount"')
+  listQuerySql = extendClause(
+    listQuerySql,
+    'SELECT',
+    '"top_selling_channels"."amount", "top_selling_channels"."nftSold"'
+  )
 
   listQuerySql = extendClause(
     listQuerySql,
@@ -139,7 +143,8 @@ export function buildTopSellingChannelsQuery(
     INNER JOIN (
       SELECT
         (SUM((COALESCE(event.data->>'price', '0')::bigint)) + SUM(COALESCE(winning_bid.amount, 0))) AS "amount",
-        "data"->'previousNftOwner'->>'channel' AS "channel_id"
+        "data"->'previousNftOwner'->>'channel' AS "channel_id",
+        COUNT("event"."data"->'previousNftOwner'->>'channel') as "nftSold"
       FROM "event"
       LEFT JOIN bid AS winning_bid ON "data"->>'winningBid' = winning_bid.id
       WHERE
@@ -170,11 +175,17 @@ export function buildTopSellingChannelsQuery(
   const oldListQMap = listQuery.map.bind(listQuery)
   listQuery.map = (rows: unknown[][]) => {
     const sellAmounts: unknown[] = []
+    const nftCount: unknown[] = []
     for (const row of rows) {
+      nftCount.push(row.pop())
       sellAmounts.push(row.pop())
     }
     const channelsMapped = oldListQMap(rows)
-    return channelsMapped.map((channel, i) => ({ channel, amount: sellAmounts[i] }))
+    return channelsMapped.map((channel, i) => ({
+      channel,
+      amount: sellAmounts[i],
+      nftSold: nftCount[i],
+    }))
   }
 
   return listQuery

+ 1 - 1
src/tests/v2/generated/queries.ts

@@ -145,7 +145,7 @@ export type GetTopSellingChannelsQueryVariables = Types.Exact<{
 
 export type GetTopSellingChannelsQuery = {
   topSellingChannels?: Types.Maybe<
-    Array<Types.Maybe<{ amount: number; channel: BasicChannelFieldsFragment }>>
+    Array<Types.Maybe<{ amount: string; channel: BasicChannelFieldsFragment }>>
   >
 }
 

+ 2 - 1
src/tests/v2/generated/schema.ts

@@ -6758,8 +6758,9 @@ export type SubscriptionVideosArgs = {
 }
 
 export type TopSellingChannelsResult = {
-  amount: Scalars['Int']
+  amount: Scalars['String']
   channel: Channel
+  nftSold: Scalars['Int']
 }
 
 export type TransactionalStatus =

+ 2 - 1
src/tests/v2/schema.graphql

@@ -355,7 +355,8 @@ type ExtendedChannel {
 
 type TopSellingChannelsResult {
   channel: Channel!
-  amount: Int!
+  amount: String!
+  nftSold: Int!
 }
 
 type ChannelNftCollector {