hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { getClassMembers, getClasses } from "@/api/classes"; |
| 2 | import { getUserSearch } from "@/api/users"; |
| 3 | import type { ClassGroup, PersonRef } from "@/api/client"; |
| 4 | |
| 5 | export 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. */ |
| 11 | export 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 | } |