forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

student-directory.ts26 lines, 1.0 KiBHistoryRawDownload
1import { getClassMembers, getClasses } from "@/api/classes";
2import { getUserSearch } from "@/api/users";
3import type { ClassGroup, PersonRef } from "@/api/client";
4
5export type StudentDirectoryRow = {
6 person: PersonRef;
7 classes: ClassGroup[];
8};
9
10/** Shared student list for teacher-facing reports: one name column and the classes it belongs to. */
11export async function getStudentDirectory(): Promise<StudentDirectoryRow[]> {
12 const [students, classes] = await Promise.all([
13 getUserSearch("", undefined, "student"),
14 getClasses({ limit: 200 }),
15 ]);
16 const byStudent = new Map<string, ClassGroup[]>();
17 const memberships = await Promise.all(
18 classes.items.map(async (cls) => ({ cls, members: (await getClassMembers(cls.id, { limit: 500 })).items })),
19 );
20 for (const { cls, members } of memberships) {
21 for (const member of members) {
22 byStudent.set(member.user.id, [...(byStudent.get(member.user.id) ?? []), cls]);
23 }
24 }
25 return students.items.map((person) => ({ person, classes: byStudent.get(person.id) ?? [] }));
26}