From 4812aba2c223d35487fd8af5f367fc939265968f Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Mon, 14 Oct 2024 14:24:17 -0600 Subject: [PATCH] fix number of NFTS purchased by a scout on their own profile (#4803) --- .../profile/components/ScoutProfile/ScoutProfile.tsx | 2 +- apps/scoutgame/lib/builders/interfaces.ts | 1 + apps/scoutgame/lib/scouts/getScoutedBuilders.ts | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx b/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx index 2eeb2737ec..956774c9f1 100644 --- a/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx +++ b/apps/scoutgame/components/profile/components/ScoutProfile/ScoutProfile.tsx @@ -25,7 +25,7 @@ export async function ScoutProfile({ userId, isMobile }: { userId: string; isMob getScoutedBuilders({ scoutId: userId }) ]); - const nftsPurchasedThisSeason = scoutedBuilders.reduce((acc, builder) => acc + (builder.nftsSold || 0), 0); + const nftsPurchasedThisSeason = scoutedBuilders.reduce((acc, builder) => acc + (builder.nftsSoldToScout || 0), 0); return ( diff --git a/apps/scoutgame/lib/builders/interfaces.ts b/apps/scoutgame/lib/builders/interfaces.ts index b0edebe225..df177755ef 100644 --- a/apps/scoutgame/lib/builders/interfaces.ts +++ b/apps/scoutgame/lib/builders/interfaces.ts @@ -22,4 +22,5 @@ export type BuilderInfo = BasicUserInfo & BuilderMetrics & { nftImageUrl?: string | null; boughtNftsCount?: number; + nftsSoldToScout?: number; }; diff --git a/apps/scoutgame/lib/scouts/getScoutedBuilders.ts b/apps/scoutgame/lib/scouts/getScoutedBuilders.ts index 8979cd2e1d..f11960d0f0 100644 --- a/apps/scoutgame/lib/scouts/getScoutedBuilders.ts +++ b/apps/scoutgame/lib/scouts/getScoutedBuilders.ts @@ -14,6 +14,7 @@ export async function getScoutedBuilders({ scoutId }: { scoutId: string }): Prom scoutId }, select: { + tokensPurchased: true, builderNFT: { select: { builderId: true @@ -72,6 +73,9 @@ export async function getScoutedBuilders({ scoutId }: { scoutId: string }): Prom }); return builders.map((builder) => { + const nftsSoldToScout = nftPurchaseEvents + .filter((event) => event.builderNFT.builderId === builder.id) + .reduce((acc, event) => acc + event.tokensPurchased, 0); return { id: builder.id, nftImageUrl: builder.builderNfts[0]?.imageUrl, @@ -81,6 +85,7 @@ export async function getScoutedBuilders({ scoutId }: { scoutId: string }): Prom builderPoints: builder.userSeasonStats[0]?.pointsEarnedAsBuilder ?? 0, gemsCollected: builder.userWeeklyStats[0]?.gemsCollected ?? 0, nftsSold: builder.userSeasonStats[0]?.nftsSold ?? 0, + nftsSoldToScout, isBanned: builder.builderStatus === 'banned', price: builder.builderNfts[0]?.currentPrice ?? 0, boughtNftsCount: undefined