diff --git a/app/(dashboard)/repo-settings/[repositoryId]/players/page.tsx b/app/(dashboard)/repo-settings/[repositoryId]/players/page.tsx index 69df5c2..1f6a3a9 100644 --- a/app/(dashboard)/repo-settings/[repositoryId]/players/page.tsx +++ b/app/(dashboard)/repo-settings/[repositoryId]/players/page.tsx @@ -1,4 +1,4 @@ -import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import UserProfileSummary from "@/components/ui/userProfileSummary"; import { getUsersForRepository } from "@/lib/repository/service"; export const metadata = { @@ -9,27 +9,35 @@ export const metadata = { export default async function RepoSettings({ params }) { const players = await getUsersForRepository(params.repositoryId); + const arrayOfPlayersWithTheirTotalPoints = players.map((player) => { + const totalPointsForThisSinglePlayer = player.pointTransactions.reduce((acc, pt) => acc + pt.points, 0); + return { + ...player, + totalPointsForThisSinglePlayer: totalPointsForThisSinglePlayer, + }; + }); + + // Sort users by total points in descending order + const arrayOfUsersInRepoInDescendingOrder = arrayOfPlayersWithTheirTotalPoints.sort( + (a, b) => b.totalPointsForThisSinglePlayer - a.totalPointsForThisSinglePlayer + ); + return (
{players.length === 0 ? (

No players enrolled in this repository.

) : ( - // Replace with Leaderboard component
- {players.map((player) => ( -
-
- - - CN - -

{player.name}

-
-
-
- ))}{" "} + {arrayOfUsersInRepoInDescendingOrder.map((player, idx) => ( + + ))}
)}
diff --git a/lib/repository/service.ts b/lib/repository/service.ts index dd9cc37..1e7a6b6 100644 --- a/lib/repository/service.ts +++ b/lib/repository/service.ts @@ -154,6 +154,7 @@ export const getUsersForRepository = async (repositoryId: string) => { }, }, }, + include: { pointTransactions: true }, }); return users;