forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

student-info-access.ts35 lines, 1.2 KiBHistoryRawDownload
1import type { Role } from "@/api/client";
2
3/**
4 * Where the "student info" panel on a student's profile reads from, per viewer:
5 *
6 * - `self` — the student themself: their own `GET /auth/me` row.
7 * - `admin` — `GET /users/{id}` (admin only): the full personal record.
8 * - `staff` — teacher / manager: `GET /users/{id}` is a 403 for them, so only
9 * the student number that `GET /users/search` carries.
10 * - `parent` — a parent linked to this student (the profile itself is a 403 for
11 * any other parent): the student's ref from `GET /users/me/students`
12 * plus the parent's own `GET /auth/me` row.
13 *
14 * `null` hides the button: another student, or a non-student profile.
15 */
16export type StudentInfoSource = "self" | "admin" | "staff" | "parent";
17
18export function studentInfoSource(
19 viewer: { id: string; role: Role } | null | undefined,
20 owner: { id: string; role: Role },
21): StudentInfoSource | null {
22 if (!viewer || owner.role !== "student") return null;
23 if (viewer.id === owner.id) return "self";
24 switch (viewer.role) {
25 case "admin":
26 return "admin";
27 case "manager":
28 case "teacher":
29 return "staff";
30 case "parent":
31 return "parent";
32 default:
33 return null;
34 }
35}