diff --git a/src/app/dashboard/info/points.tsx b/src/app/dashboard/info/points.tsx index ecf1629..92c99f2 100644 --- a/src/app/dashboard/info/points.tsx +++ b/src/app/dashboard/info/points.tsx @@ -2,66 +2,31 @@ import { Column } from 'primereact/column' import { DataTable } from 'primereact/datatable' -import { JsonUser } from '@/lib/db/models/User' - -import { AppPermissions } from '@/lib/db/models/Role' -import { useImmer } from 'use-immer' - export interface UserDataTableProps { - users: JsonUser[] - perms: AppPermissions - allRoles: readonly string[] + users: { name: string; pointsObtained: number }[] } export default function UserDataTable({ - users: initialUsers, + users, }: UserDataTableProps) { - const [users] = useImmer(initialUsers) - - const sortedUsers = [...users].sort((a, b) => - (b.pointsObtained || 0) - (a.pointsObtained || 0) - ) - - const modifiedUsers = sortedUsers.map((user) => { - return { - ...user, - pointsObtained: user.pointsObtained === undefined - ? 0 - : user.pointsObtained, - } - }) - return (

Leaderboard

- - - ('roles') - .find({}, { projection: { granted: 0 } }) - .toArray() - const users = await client.db() + const users = (await client.db() .collection('users') - .find({}, { projection: { 'application.resume': 0 } }) - .toArray() + .find({ pointsObtained: { $gt: 0 } }, { + projection: { 'application.resume': 0 }, + }) + .sort({ pointsObtained: 'descending' }) + .toArray()) + .map((u) => ({ name: getFullName(u), pointsObtained: u.pointsObtained! })) return ( <> r._id)} - users={JSON.parse(JSON.stringify(users))} - perms={perms} + users={users} />