From c818af537bc443135b043a88aaea4add230104a3 Mon Sep 17 00:00:00 2001 From: Taufik Hidayat Date: Sun, 7 Jul 2024 08:36:29 +0700 Subject: [PATCH] feat(leaderboard): show user's leaderboard --- src/app/_components/sidebar/most-active-users.tsx | 10 ++++++++-- src/server/api/routers/user.ts | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/_components/sidebar/most-active-users.tsx b/src/app/_components/sidebar/most-active-users.tsx index 9c99057..c48f4be 100644 --- a/src/app/_components/sidebar/most-active-users.tsx +++ b/src/app/_components/sidebar/most-active-users.tsx @@ -23,7 +23,7 @@ export function MostActiveUsers({
    - {data.map(({ user }, index) => ( + {data.map(({ user, score }, index) => (
  1. {index + 1}. @@ -41,7 +41,7 @@ export function MostActiveUsers({ }} /> -
    +
    +

    + {score} +

  2. ))}
diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts index ba29fa9..442b411 100644 --- a/src/server/api/routers/user.ts +++ b/src/server/api/routers/user.ts @@ -190,6 +190,7 @@ export const userRouter = createTRPCRouter({ const data = await ctx.db .select({ user: users, + score, }) .from(users) .leftJoin(questions, eq(questions.userId, users.id)) @@ -219,11 +220,13 @@ export const userRouter = createTRPCRouter({ gt(memberships.expiresAt, new Date()), ), ); + return data.map((dt) => ({ user: { ...dt.user, membership: _memberships.find((mb) => mb.userId === dt.user.id), }, + score: dt.score, })); }), });