From 045bfdfc0f1c37af70735c8d13e01ee42f74cf7f Mon Sep 17 00:00:00 2001 From: mattcasey Date: Fri, 1 Nov 2024 15:29:00 -0600 Subject: [PATCH 1/4] always show a users current week rank --- apps/scoutgame/lib/builders/getSortedBuilders.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/scoutgame/lib/builders/getSortedBuilders.ts b/apps/scoutgame/lib/builders/getSortedBuilders.ts index d4bc9ccc5c..2c535c26a2 100644 --- a/apps/scoutgame/lib/builders/getSortedBuilders.ts +++ b/apps/scoutgame/lib/builders/getSortedBuilders.ts @@ -238,6 +238,14 @@ export async function getSortedBuilders({ path: true, displayName: true, builderStatus: true, + userWeeklyStats: { + where: { + week + }, + select: { + rank: true + } + }, userAllTimeStats: { select: { pointsEarnedAsBuilder: true @@ -272,7 +280,7 @@ export async function getSortedBuilders({ .then((stats) => stats.map((stat) => ({ id: stat.user.id, - rank: stat.rank ?? -1, + rank: stat.user.userWeeklyStats[0]?.rank ?? -1, nftImageUrl: stat.user.builderNfts[0]?.imageUrl, path: stat.user.path, displayName: stat.user.displayName, From 9dcdd6407de8141b458eee55e40f40003965586f Mon Sep 17 00:00:00 2001 From: mattcasey Date: Fri, 1 Nov 2024 15:33:19 -0600 Subject: [PATCH 2/4] add test --- .../lib/builders/__tests__/getSortedBuilders.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts b/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts index 1bf07a1770..2c9d8d62bd 100644 --- a/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts +++ b/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts @@ -72,6 +72,12 @@ describe('getSortedBuilders', () => { week: getPreviousWeek(mockWeek), rank: 2 }); + // rank should be pulled from the current week + await mockUserWeeklyStats({ + userId: builders[1].id, + week: mockWeek, + rank: 999 + }); const { builders: paginatedBuilders } = await getSortedBuilders({ sort: 'top', limit: 3, @@ -80,6 +86,7 @@ describe('getSortedBuilders', () => { cursor: null }); expect(paginatedBuilders.map((r) => r.id)).toEqual([builders[1].id, builders[0].id]); + expect(paginatedBuilders[0].rank).toEqual(999); }); it('should skip builders without nfts', async () => { From ecd962500043eaf784b6b01a6589a1c9114be90a Mon Sep 17 00:00:00 2001 From: mattcasey Date: Fri, 1 Nov 2024 15:37:46 -0600 Subject: [PATCH 3/4] fix query --- apps/scoutgame/lib/builders/getSortedBuilders.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/scoutgame/lib/builders/getSortedBuilders.ts b/apps/scoutgame/lib/builders/getSortedBuilders.ts index 2c535c26a2..2fcb93bfa4 100644 --- a/apps/scoutgame/lib/builders/getSortedBuilders.ts +++ b/apps/scoutgame/lib/builders/getSortedBuilders.ts @@ -67,7 +67,8 @@ export async function getSortedBuilders({ }, userWeeklyStats: { where: { - week + week, + season }, select: { rank: true @@ -231,7 +232,6 @@ export async function getSortedBuilders({ } : undefined, select: { - rank: true, user: { select: { id: true, @@ -240,7 +240,8 @@ export async function getSortedBuilders({ builderStatus: true, userWeeklyStats: { where: { - week + week, + season }, select: { rank: true From 1b000456956c95f583d8fa963d77ddd2fab05aab Mon Sep 17 00:00:00 2001 From: mattcasey Date: Fri, 1 Nov 2024 22:11:33 -0600 Subject: [PATCH 4/4] fix tests --- .../scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts b/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts index 2c9d8d62bd..0358da79d1 100644 --- a/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts +++ b/apps/scoutgame/lib/builders/__tests__/getSortedBuilders.spec.ts @@ -65,17 +65,20 @@ describe('getSortedBuilders', () => { await mockUserWeeklyStats({ userId: builders[0].id, week: getPreviousWeek(mockWeek), + season: mockSeason, rank: 5 }); await mockUserWeeklyStats({ userId: builders[1].id, week: getPreviousWeek(mockWeek), + season: mockSeason, rank: 2 }); // rank should be pulled from the current week await mockUserWeeklyStats({ userId: builders[1].id, week: mockWeek, + season: mockSeason, rank: 999 }); const { builders: paginatedBuilders } = await getSortedBuilders({