Revamped the statistical page to work with the new entity system, along with some other improvements to it

This commit is contained in:
Tiago Ribeiro
2024-11-21 15:37:53 +00:00
parent 0eed8e4612
commit f301001ebe
8 changed files with 1052 additions and 541 deletions

View File

@@ -1,4 +1,4 @@
import {Session} from "@/hooks/useSessions";
import { Session } from "@/hooks/useSessions";
import client from "@/lib/mongodb";
const db = client.db(process.env.MONGODB_DB);
@@ -6,11 +6,16 @@ const db = client.db(process.env.MONGODB_DB);
export const getSessionsByUser = async (id: string, limit = 0, filter = {}) =>
await db
.collection("sessions")
.find<Session>({user: id, ...filter})
.find<Session>({ user: id, ...filter })
.limit(limit || 0)
.toArray();
export const getSessionByAssignment = async (assignmentID: string) =>
await db
.collection("sessions")
.findOne<Session>({"assignment.id": assignmentID})
.collection("sessions")
.findOne<Session>({ "assignment.id": assignmentID })
export const getSessionsByAssignments = async (assignmentIDs: string[]) =>
await db
.collection("sessions")
.find<Session>({ "assignment.id": { $in: assignmentIDs } }).toArray()