forge
Explore
Log in

Don't you dare go Hollow

🔌 align backend contracts

Browse files at this commit

4e531e5af0fe1ff5f1d0c66a8112706add16cbfcBurak BoduroğluParent: f9872a0
  • feat
    • 🔌 align backend contracts
Show full message
feat(api): 🔌 align backend contracts

- add runtime limits and complete meal endpoint clients

- align course, homework, report, and settings payloads

- drive auth validation from server limits
src/api/__tests__/courses/courses.test.tsmodified+6 -0
@@ -60,6 +60,12 @@ describe("courses API", () => {
60 expect(init?.method).toBe("GET");60 expect(init?.method).toBe("GET");
61 });61 });
62 62
63+ it("getCourses sends server-side kind, search, and term filters", async () => {
64+ mockFetchSuccess({ items: [], total: 0 });
65+ await getCourses({ limit: 12, offset: 24, kind: "course", q: "math", term_id: "none" });
66+ expect(lastFetchCall()[0]).toBe("/api/courses?limit=12&offset=24&kind=course&q=math&term_id=none");
67+ });
68+
63 it("getCourseById calls /courses/:id", async () => {69 it("getCourseById calls /courses/:id", async () => {
64 const mockCourse = { id: "c1", title: "Course" };70 const mockCourse = { id: "c1", title: "Course" };
65 mockFetchSuccess(mockCourse);71 mockFetchSuccess(mockCourse);
src/api/__tests__/homework/homework.test.tsmodified+6 -0
@@ -37,6 +37,12 @@ describe("homework API", () => {
37 expect(init?.method).toBe("GET");37 expect(init?.method).toBe("GET");
38 });38 });
39 39
40+ it("getHomework sends due_after", async () => {
41+ mockFetchSuccess({ items: [], total: 0 });
42+ await getHomework({ limit: 1, due_after: 1_700_000_000_000 });
43+ expect(lastFetchCall()[0]).toBe("/api/homework?limit=1&due_after=1700000000000");
44+ });
45+
40 it("getHomeworkById calls /homework/:id", async () => {46 it("getHomeworkById calls /homework/:id", async () => {
41 const mockHomework = { id: "hw1" };47 const mockHomework = { id: "hw1" };
42 mockFetchSuccess(mockHomework);48 mockFetchSuccess(mockHomework);
src/api/__tests__/limits/limits.test.tsadded+19 -0
@@ -0,0 +1,19 @@
1+import { afterEach, describe, expect, it, vi } from "vitest";
2+import { getLimits, setCachedLimits } from "../../limits";
3+import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch";
4+
5+describe("limits API", () => {
6+ afterEach(() => {
7+ vi.restoreAllMocks();
8+ setCachedLimits(null);
9+ });
10+
11+ it("loads /limits once and caches it", async () => {
12+ mockFetchSuccess({ user: { min_username_len: 3 } });
13+ await getLimits();
14+ expect(lastFetchCall()[0]).toBe("/api/limits");
15+ vi.mocked(globalThis.fetch).mockClear();
16+ await getLimits();
17+ expect(globalThis.fetch).not.toHaveBeenCalled();
18+ });
19+});
src/api/__tests__/meals/meals.test.tsadded+79 -0
@@ -0,0 +1,79 @@
1+import { afterEach, describe, expect, it, vi } from "vitest";
2+import {
3+ deleteMealBookingById,
4+ deleteMealDishById,
5+ deleteMealMenuById,
6+ getDietaryProfileByUserId,
7+ getMealAttendanceByUserId,
8+ getMealBalanceByUserId,
9+ getMealLedgerByUserId,
10+ getMealMenuBookings,
11+ getMealMenuById,
12+ getMealMenus,
13+ getMealServiceRoster,
14+ getMyDietaryProfile,
15+ getMyMealBalance,
16+ getMyMealBookings,
17+ patchDietaryProfileByUserId,
18+ patchMealDishById,
19+ patchMealMenuById,
20+ postMealAttendance,
21+ postMealBooking,
22+ postMealCredit,
23+ postMealDish,
24+ postMealMenu,
25+} from "../../meals";
26+import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
27+
28+describe("meals API", () => {
29+ afterEach(() => vi.restoreAllMocks());
30+ const json = () => mockFetchSuccess({});
31+ const page = () => mockFetchSuccess({ items: [], total: 0 });
32+
33+ it("lists menus with dates and pagination", async () => {
34+ page(); await getMealMenus({ from: "2026-07-28", to: "2026-08-01", limit: 12, offset: 12 });
35+ expect(lastFetchCall()[0]).toBe("/api/meals/menus?limit=12&offset=12&from=2026-07-28&to=2026-08-01");
36+ });
37+ it("gets a menu", async () => { json(); await getMealMenuById("m/1"); expect(lastFetchCall()[0]).toBe("/api/meals/menus/m%2F1"); });
38+ it("publishes a menu", async () => {
39+ json(); const body = { date: "2026-07-28", slot: "lunch", capacity: 10 }; await postMealMenu(body);
40+ expect(lastFetchCall()).toMatchObject(["/api/meals/menus", { method: "POST", body: JSON.stringify(body) }]);
41+ });
42+ it("patches a menu", async () => {
43+ json(); await patchMealMenuById("m1", { capacity: null });
44+ expect(lastFetchCall()).toMatchObject(["/api/meals/menus/m1", { method: "PATCH", body: JSON.stringify({ capacity: null }) }]);
45+ });
46+ it("deletes a menu", async () => { mockFetch204(); await deleteMealMenuById("m1"); expect(lastFetchCall()).toMatchObject(["/api/meals/menus/m1", { method: "DELETE" }]); });
47+ it("adds a dish", async () => {
48+ json(); const body = { name: "Soup", description: null, price_minor: 4500, tags: ["vegan"] }; await postMealDish("m1", body);
49+ expect(lastFetchCall()).toMatchObject(["/api/meals/menus/m1/dishes", { method: "POST", body: JSON.stringify(body) }]);
50+ });
51+ it("patches a dish", async () => { json(); await patchMealDishById("d1", { price_minor: 5000 }); expect(lastFetchCall()).toMatchObject(["/api/meals/dishes/d1", { method: "PATCH", body: JSON.stringify({ price_minor: 5000 }) }]); });
52+ it("deletes a dish", async () => { mockFetch204(); await deleteMealDishById("d1"); expect(lastFetchCall()).toMatchObject(["/api/meals/dishes/d1", { method: "DELETE" }]); });
53+ it("gets own profile", async () => { json(); await getMyDietaryProfile(); expect(lastFetchCall()[0]).toBe("/api/meals/profiles/me"); });
54+ it("gets a student profile", async () => { json(); await getDietaryProfileByUserId("u1"); expect(lastFetchCall()[0]).toBe("/api/meals/profiles/u1"); });
55+ it("patches a student profile", async () => {
56+ json(); const body = { tags: ["nuts"], note: null }; await patchDietaryProfileByUserId("u1", body);
57+ expect(lastFetchCall()).toMatchObject(["/api/meals/profiles/u1", { method: "PATCH", body: JSON.stringify(body) }]);
58+ });
59+ it("books a child seat", async () => {
60+ json(); await postMealBooking("m1", "u1");
61+ expect(lastFetchCall()).toMatchObject(["/api/meals/menus/m1/bookings", { method: "POST", body: JSON.stringify({ student_id: "u1" }) }]);
62+ });
63+ it("lists own bookings", async () => { page(); await getMyMealBookings({ limit: 20 }); expect(lastFetchCall()[0]).toBe("/api/meals/bookings/me?limit=20"); });
64+ it("cancels a booking", async () => { json(); await deleteMealBookingById("b1"); expect(lastFetchCall()).toMatchObject(["/api/meals/bookings/b1", { method: "DELETE" }]); });
65+ it("lists booking audit", async () => { page(); await getMealMenuBookings("m1", { limit: 20 }); expect(lastFetchCall()[0]).toBe("/api/meals/menus/m1/bookings?limit=20"); });
66+ it("lists the service roster", async () => { page(); await getMealServiceRoster("m1", { limit: 20 }); expect(lastFetchCall()[0]).toBe("/api/meals/menus/m1/service-roster?limit=20"); });
67+ it("marks service", async () => {
68+ json(); await postMealAttendance("m1", "u1", "served");
69+ expect(lastFetchCall()).toMatchObject(["/api/meals/menus/m1/attendance", { method: "POST", body: JSON.stringify({ student_id: "u1", status: "served" }) }]);
70+ });
71+ it("gets attendance history", async () => { page(); await getMealAttendanceByUserId("u1", { from: "2026-07-01", limit: 20 }); expect(lastFetchCall()[0]).toBe("/api/meals/attendance/u1?limit=20&from=2026-07-01"); });
72+ it("gets own balance", async () => { json(); await getMyMealBalance(); expect(lastFetchCall()[0]).toBe("/api/meals/balance/me"); });
73+ it("gets student balance", async () => { json(); await getMealBalanceByUserId("u1"); expect(lastFetchCall()[0]).toBe("/api/meals/balance/u1"); });
74+ it("gets student ledger", async () => { page(); await getMealLedgerByUserId("u1", { limit: 20 }); expect(lastFetchCall()[0]).toBe("/api/meals/ledger/u1?limit=20"); });
75+ it("records append-only credit", async () => {
76+ json(); const body = { student_id: "u1", amount_minor: 10000, method: "cash", note: "receipt" }; await postMealCredit(body);
77+ expect(lastFetchCall()).toMatchObject(["/api/meals/credits", { method: "POST", body: JSON.stringify(body) }]);
78+ });
79+});
src/api/__tests__/reports/reports.test.tsmodified+6 -0
@@ -23,6 +23,12 @@ describe("reports API", () => {
23 expect(init?.method).toBe("GET");23 expect(init?.method).toBe("GET");
24 });24 });
25 25
26+ it("getMyCourses sends course filters", async () => {
27+ mockFetchSuccess({ items: [], total: 0 });
28+ await getMyCourses({ kind: "club", q: "robot", term_id: "t1" });
29+ expect(lastFetchCall()[0]).toBe("/api/courses/me?kind=club&q=robot&term_id=t1");
30+ });
31+
26 it("getMyAttendance calls /attendance/me", async () => {32 it("getMyAttendance calls /attendance/me", async () => {
27 const mockAttendance = { courses: [] };33 const mockAttendance = { courses: [] };
28 mockFetchSuccess(mockAttendance);34 mockFetchSuccess(mockAttendance);
src/api/__tests__/settings/settings.test.tsmodified+17 -0
@@ -46,4 +46,21 @@ describe("settings API", () => {
46 expect(cached).toEqual(mockSettings);46 expect(cached).toEqual(mockSettings);
47 expect(globalThis.fetch).not.toHaveBeenCalled();47 expect(globalThis.fetch).not.toHaveBeenCalled();
48 });48 });
49+
50+ it("patchSettings preserves nullable meal cutoff and expanded policy fields", async () => {
51+ mockFetchSuccess({ meal_cancel_cutoff_minutes: null });
52+ const updates = {
53+ chatbot_history_turns: 8,
54+ max_chatbot_threads: 20,
55+ max_chatbot_message_len: 3000,
56+ meal_slots: [{ name: "lunch", serving_minute: 540 }],
57+ dietary_tags: ["nuts"],
58+ meal_cancel_cutoff_minutes: null,
59+ };
60+ await patchSettings(updates);
61+ const [url, init] = lastFetchCall();
62+ expect(url).toBe("/api/settings");
63+ expect(init?.method).toBe("PATCH");
64+ expect(init?.body).toBe(JSON.stringify(updates));
65+ });
49 });66 });
src/api/client/types.tsmodified+195 -10
@@ -437,24 +437,139 @@ export type GradeBand = {
437 label: string;437 label: string;
438 };438 };
439 439
440+export type MealSlot = {
441+ name: string;
442+ serving_minute: number | null;
443+};
444+
440 export type SchoolSettings = {445 export type SchoolSettings = {
441 exam_kinds: ExamKindSetting[];446 exam_kinds: ExamKindSetting[];
442 attendance_statuses: string[];447 attendance_statuses: string[];
443 grade_bands: GradeBand[];448 grade_bands: GradeBand[];
444 max_file_bytes: number;449 max_file_bytes: number;
450+ chatbot_history_turns: number;
451+ max_chatbot_threads: number;
452+ max_chatbot_message_len: number;
453+ meal_slots: MealSlot[];
454+ dietary_tags: string[];
455+ meal_cancel_cutoff_minutes: number | null;
456+};
457+
458+export type Limits = {
459+ user: {
460+ min_username_len: number;
461+ max_username_len: number;
462+ username_separators: string[];
463+ reserved_usernames: string[];
464+ min_password_len: number;
465+ max_password_len: number;
466+ max_name_len: number;
467+ max_email_len: number;
468+ min_phone_digits: number;
469+ max_phone_digits: number;
470+ roles: Role[];
471+ themes: UserTheme[];
472+ languages: UserLanguage[];
473+ session_duration_days: number;
474+ };
475+ note: { max_title_len: number; max_content_len: number; max_files: number };
476+ file: {
477+ max_name_len: number;
478+ max_content_type_len: number;
479+ min_max_file_bytes: number;
480+ max_max_file_bytes: number;
481+ default_max_file_bytes: number;
482+ image_content_types: string[];
483+ };
484+ message: { max_subject_len: number; max_body_len: number; max_label_len: number };
485+ event: { max_title_len: number; max_description_len: number };
486+ course: {
487+ max_title_len: number;
488+ max_description_len: number;
489+ kinds: CourseKind[];
490+ max_subject_name_len: number;
491+ max_subject_description_len: number;
492+ max_session_topic_len: number;
493+ max_term_name_len: number;
494+ };
495+ exam: {
496+ max_title_len: number;
497+ max_description_len: number;
498+ modes: ExamMode[];
499+ min_duration_ms: number;
500+ max_duration_ms: number;
501+ max_attempts: number;
502+ unlimited_attempts: number;
503+ question_kinds: QuestionKind[];
504+ max_question_text_len: number;
505+ min_question_points: number;
506+ max_question_points: number;
507+ min_question_choices: number;
508+ max_question_choices: number;
509+ max_choice_text_len: number;
510+ max_answer_text_len: number;
511+ min_mark: number;
512+ max_mark: number;
513+ ws_tick_secs: number;
514+ ws_max_question_id_len: number;
515+ };
516+ homework: {
517+ max_title_len: number;
518+ max_description_len: number;
519+ max_text_len: number;
520+ max_files_per_submission: number;
521+ max_assigned: number;
522+ statuses: string[];
523+ };
524+ question_pool: { max_title_len: number; max_body_len: number; max_solution_body_len: number };
525+ appointment: { max_note_len: number; max_reason_len: number; max_slot_occurrences: number };
526+ meal: {
527+ max_dish_name_len: number;
528+ max_dish_description_len: number;
529+ max_dishes_per_menu: number;
530+ max_dish_tags: number;
531+ max_menu_capacity: number;
532+ max_dietary_tags: number;
533+ max_dietary_note_len: number;
534+ max_dish_price_minor: number;
535+ max_ledger_amount_minor: number;
536+ max_ledger_method_len: number;
537+ max_ledger_note_len: number;
538+ max_cancel_cutoff_minutes: number;
539+ max_serving_minute: number;
540+ booking_statuses: string[];
541+ attendance_statuses: string[];
542+ ledger_kinds: string[];
543+ };
544+ chatbot: {
545+ max_message_len: number;
546+ max_thread_title_len: number;
547+ min_max_message_len: number;
548+ max_max_message_len: number;
549+ default_max_message_len: number;
550+ min_history_turns: number;
551+ max_history_turns: number;
552+ default_history_turns: number;
553+ min_max_threads: number;
554+ max_max_threads: number;
555+ default_max_threads: number;
556+ };
557+ settings: {
558+ max_list_len: number;
559+ max_item_len: number;
560+ min_exam_kind_weight: number;
561+ max_exam_kind_weight: number;
562+ max_grade_bands: number;
563+ max_grade_label_len: number;
564+ required_attendance_statuses: string[];
565+ };
566+ request: { max_page_limit: number; schedule_past_grace_ms: number; request_timeout_secs: number };
567+ rate: { window_secs: number; auth_per_minute: number; api_per_minute: number; chatbot_per_minute: number };
445 };568 };
446 569
447-export const EXAM_KINDS: KnownExamKind[] = [570+// Fallbacks keep forms usable when the unauthenticated metadata request fails.
448- "homework",571+export const EXAM_KINDS: KnownExamKind[] = ["homework", "quiz", "midterm", "final", "project", "oral"];
449- "quiz",
450- "midterm",
451- "final",
452- "project",
453- "oral",
454-];
455-
456 export const EXAM_MODES: ExamMode[] = ["sync", "async", "open"];572 export const EXAM_MODES: ExamMode[] = ["sync", "async", "open"];
457-
458 export const QUESTION_KINDS: QuestionKind[] = ["choice", "text"];573 export const QUESTION_KINDS: QuestionKind[] = ["choice", "text"];
459 574
460 export type MessageFolder = "inbox" | "sent" | "archive" | "trash";575 export type MessageFolder = "inbox" | "sent" | "archive" | "trash";
@@ -534,3 +649,73 @@ export type HomeworkReportEntry = {
534 missing: boolean;649 missing: boolean;
535 result: HomeworkResult | null;650 result: HomeworkResult | null;
536 };651 };
652+
653+export type MealDish = {
654+ id: string;
655+ name: string;
656+ description: string | null;
657+ price_minor: number;
658+ tags: string[];
659+ conflicts: string[];
660+ created_at: number;
661+};
662+
663+export type MealMenu = {
664+ id: string;
665+ date: string;
666+ slot: string;
667+ capacity: number | null;
668+ dishes: MealDish[];
669+ created_by: PersonRef;
670+ created_at: number;
671+};
672+
673+export type MealBooking = {
674+ id: string;
675+ menu_id: string;
676+ student: PersonRef;
677+ booked_by: PersonRef;
678+ status: string;
679+ cancelled_at: number | null;
680+ created_at: number;
681+};
682+
683+export type MealAttendance = {
684+ id: string;
685+ menu_id: string;
686+ student: PersonRef;
687+ status: string;
688+ marked_by: PersonRef;
689+ marked_at: number;
690+};
691+
692+export type MealServiceRosterEntry = {
693+ student: PersonRef;
694+ booking: MealBooking | null;
695+ attendance: MealAttendance | null;
696+};
697+
698+export type DietaryProfile = {
699+ student: PersonRef;
700+ tags: string[];
701+ note: string | null;
702+ updated_by: PersonRef | null;
703+ updated_at: number | null;
704+};
705+
706+export type MealBalance = {
707+ student: PersonRef;
708+ balance_minor: number;
709+};
710+
711+export type MealLedgerEntry = {
712+ id: string;
713+ student: PersonRef;
714+ kind: string;
715+ amount_minor: number;
716+ source: string | null;
717+ method: string | null;
718+ note: string | null;
719+ recorded_by: PersonRef;
720+ created_at: number;
721+};
src/api/courses/getCourses.tsmodified+21 -4
@@ -1,8 +1,25 @@
1 import { client } from "../client";1 import { client } from "../client";
2-import { normalizePage, pageQuery, type Page, type PageParams } from "../client";2+import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3-import type { Course } from "../client";3+import type { Course, CourseKind } from "../client";
4 4
5-export async function getCourses(params?: PageParams, signal?: AbortSignal): Promise<Page<Course>> {5+export type CourseListParams = PageParams & {
6- const data = await client<unknown>(`/courses${pageQuery(params)}`, { signal });6+ kind?: CourseKind;
7+ q?: string;
8+ term_id?: string;
9+};
10+
11+export function courseListQuery(params?: CourseListParams): string {
12+ if (!params) return "";
13+ const query = new URLSearchParams();
14+ appendPageParams(query, params);
15+ if (params.kind) query.set("kind", params.kind);
16+ if (params.q) query.set("q", params.q);
17+ if (params.term_id) query.set("term_id", params.term_id);
18+ const value = query.toString();
19+ return value ? `?${value}` : "";
20+}
21+
22+export async function getCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> {
23+ const data = await client<unknown>(`/courses${courseListQuery(params)}`, { signal });
7 return normalizePage<Course>(data);24 return normalizePage<Course>(data);
8 }25 }
src/api/homework/getHomework.tsmodified+9 -3
@@ -1,8 +1,14 @@
1 import { client } from "../client";1 import { client } from "../client";
2-import { normalizePage, pageQuery, type Page, type PageParams } from "../client";2+import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3 import type { Homework } from "../client";3 import type { Homework } from "../client";
4 4
5-export async function getHomework(params?: PageParams, signal?: AbortSignal): Promise<Page<Homework>> {5+export type HomeworkListParams = PageParams & { due_after?: number };
6- const data = await client<unknown>(`/homework${pageQuery(params)}`, { signal });6+
7+export async function getHomework(params?: HomeworkListParams, signal?: AbortSignal): Promise<Page<Homework>> {
8+ const query = new URLSearchParams();
9+ appendPageParams(query, params);
10+ if (params?.due_after != null) query.set("due_after", String(params.due_after));
11+ const suffix = query.size ? `?${query}` : "";
12+ const data = await client<unknown>(`/homework${suffix}`, { signal });
7 return normalizePage<Homework>(data);13 return normalizePage<Homework>(data);
8 }14 }
src/api/limits/getLimits.tsadded+21 -0
@@ -0,0 +1,21 @@
1+import { client } from "../client";
2+import type { Limits } from "../client";
3+
4+let cachedLimits: Limits | null = null;
5+let pendingLimits: Promise<Limits> | null = null;
6+
7+export function getLimits(signal?: AbortSignal): Promise<Limits> {
8+ if (cachedLimits) return Promise.resolve(cachedLimits);
9+ if (pendingLimits) return pendingLimits;
10+ pendingLimits = client<Limits>("/limits", { signal })
11+ .then((limits) => (cachedLimits = limits))
12+ .finally(() => {
13+ pendingLimits = null;
14+ });
15+ return pendingLimits;
16+}
17+
18+export function setCachedLimits(limits: Limits | null): void {
19+ cachedLimits = limits;
20+ pendingLimits = null;
21+}
src/api/limits/index.tsadded+1 -0
@@ -0,0 +1 @@
1+export * from "./getLimits";
src/api/meals/deleteMealBookingById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealBooking } from "../client";
3+
4+export function deleteMealBookingById(id: string): Promise<MealBooking> {
5+ return client<MealBooking>(`/meals/bookings/${encodeURIComponent(id)}`, { method: "DELETE" });
6+}
src/api/meals/deleteMealDishById.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteMealDishById(id: string): Promise<void> {
4+ return client<void>(`/meals/dishes/${encodeURIComponent(id)}`, { method: "DELETE" });
5+}
src/api/meals/deleteMealMenuById.tsadded+5 -0
@@ -0,0 +1,5 @@
1+import { client } from "../client";
2+
3+export function deleteMealMenuById(id: string): Promise<void> {
4+ return client<void>(`/meals/menus/${encodeURIComponent(id)}`, { method: "DELETE" });
5+}
src/api/meals/getDietaryProfileByUserId.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { DietaryProfile } from "../client";
3+
4+export function getDietaryProfileByUserId(userId: string, signal?: AbortSignal): Promise<DietaryProfile> {
5+ return client<DietaryProfile>(`/meals/profiles/${encodeURIComponent(userId)}`, { signal });
6+}
src/api/meals/getMealAttendanceByUserId.tsadded+19 -0
@@ -0,0 +1,19 @@
1+import { client } from "../client";
2+import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3+import type { MealAttendance } from "../client";
4+
5+export async function getMealAttendanceByUserId(
6+ userId: string,
7+ params?: PageParams & { from?: string; to?: string },
8+ signal?: AbortSignal,
9+): Promise<Page<MealAttendance>> {
10+ const query = new URLSearchParams();
11+ appendPageParams(query, params);
12+ if (params?.from) query.set("from", params.from);
13+ if (params?.to) query.set("to", params.to);
14+ const data = await client<unknown>(
15+ `/meals/attendance/${encodeURIComponent(userId)}${query.size ? `?${query}` : ""}`,
16+ { signal },
17+ );
18+ return normalizePage<MealAttendance>(data);
19+}
src/api/meals/getMealBalanceByUserId.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealBalance } from "../client";
3+
4+export function getMealBalanceByUserId(userId: string, signal?: AbortSignal): Promise<MealBalance> {
5+ return client<MealBalance>(`/meals/balance/${encodeURIComponent(userId)}`, { signal });
6+}
src/api/meals/getMealLedgerByUserId.tsadded+12 -0
@@ -0,0 +1,12 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { MealLedgerEntry } from "../client";
4+
5+export async function getMealLedgerByUserId(
6+ userId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<MealLedgerEntry>> {
10+ const data = await client<unknown>(`/meals/ledger/${encodeURIComponent(userId)}${pageQuery(params)}`, { signal });
11+ return normalizePage<MealLedgerEntry>(data);
12+}
src/api/meals/getMealMenuBookings.tsadded+15 -0
@@ -0,0 +1,15 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { MealBooking } from "../client";
4+
5+export async function getMealMenuBookings(
6+ menuId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<MealBooking>> {
10+ const data = await client<unknown>(
11+ `/meals/menus/${encodeURIComponent(menuId)}/bookings${pageQuery(params)}`,
12+ { signal },
13+ );
14+ return normalizePage<MealBooking>(data);
15+}
src/api/meals/getMealMenuById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealMenu } from "../client";
3+
4+export function getMealMenuById(id: string, signal?: AbortSignal): Promise<MealMenu> {
5+ return client<MealMenu>(`/meals/menus/${encodeURIComponent(id)}`, { signal });
6+}
src/api/meals/getMealMenus.tsadded+14 -0
@@ -0,0 +1,14 @@
1+import { client } from "../client";
2+import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3+import type { MealMenu } from "../client";
4+
5+export type MealMenuParams = PageParams & { from?: string; to?: string };
6+
7+export async function getMealMenus(params?: MealMenuParams, signal?: AbortSignal): Promise<Page<MealMenu>> {
8+ const query = new URLSearchParams();
9+ appendPageParams(query, params);
10+ if (params?.from) query.set("from", params.from);
11+ if (params?.to) query.set("to", params.to);
12+ const data = await client<unknown>(`/meals/menus${query.size ? `?${query}` : ""}`, { signal });
13+ return normalizePage<MealMenu>(data);
14+}
src/api/meals/getMealServiceRoster.tsadded+15 -0
@@ -0,0 +1,15 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { MealServiceRosterEntry } from "../client";
4+
5+export async function getMealServiceRoster(
6+ menuId: string,
7+ params?: PageParams,
8+ signal?: AbortSignal,
9+): Promise<Page<MealServiceRosterEntry>> {
10+ const data = await client<unknown>(
11+ `/meals/menus/${encodeURIComponent(menuId)}/service-roster${pageQuery(params)}`,
12+ { signal },
13+ );
14+ return normalizePage<MealServiceRosterEntry>(data);
15+}
src/api/meals/getMyDietaryProfile.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { DietaryProfile } from "../client";
3+
4+export function getMyDietaryProfile(signal?: AbortSignal): Promise<DietaryProfile> {
5+ return client<DietaryProfile>("/meals/profiles/me", { signal });
6+}
src/api/meals/getMyMealBalance.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealBalance } from "../client";
3+
4+export function getMyMealBalance(signal?: AbortSignal): Promise<MealBalance> {
5+ return client<MealBalance>("/meals/balance/me", { signal });
6+}
src/api/meals/getMyMealBookings.tsadded+8 -0
@@ -0,0 +1,8 @@
1+import { client } from "../client";
2+import { normalizePage, pageQuery, type Page, type PageParams } from "../client";
3+import type { MealBooking } from "../client";
4+
5+export async function getMyMealBookings(params?: PageParams, signal?: AbortSignal): Promise<Page<MealBooking>> {
6+ const data = await client<unknown>(`/meals/bookings/me${pageQuery(params)}`, { signal });
7+ return normalizePage<MealBooking>(data);
8+}
src/api/meals/index.tsadded+22 -0
@@ -0,0 +1,22 @@
1+export * from "./deleteMealBookingById";
2+export * from "./deleteMealDishById";
3+export * from "./deleteMealMenuById";
4+export * from "./getDietaryProfileByUserId";
5+export * from "./getMealAttendanceByUserId";
6+export * from "./getMealBalanceByUserId";
7+export * from "./getMealLedgerByUserId";
8+export * from "./getMealMenuById";
9+export * from "./getMealMenuBookings";
10+export * from "./getMealMenus";
11+export * from "./getMealServiceRoster";
12+export * from "./getMyDietaryProfile";
13+export * from "./getMyMealBalance";
14+export * from "./getMyMealBookings";
15+export * from "./patchDietaryProfileByUserId";
16+export * from "./patchMealDishById";
17+export * from "./patchMealMenuById";
18+export * from "./postMealAttendance";
19+export * from "./postMealBooking";
20+export * from "./postMealCredit";
21+export * from "./postMealDish";
22+export * from "./postMealMenu";
src/api/meals/patchDietaryProfileByUserId.tsadded+9 -0
@@ -0,0 +1,9 @@
1+import { client } from "../client";
2+import type { DietaryProfile } from "../client";
3+
4+export function patchDietaryProfileByUserId(
5+ userId: string,
6+ body: { tags?: string[]; note?: string | null },
7+): Promise<DietaryProfile> {
8+ return client<DietaryProfile>(`/meals/profiles/${encodeURIComponent(userId)}`, { method: "PATCH", body });
9+}
src/api/meals/patchMealDishById.tsadded+7 -0
@@ -0,0 +1,7 @@
1+import { client } from "../client";
2+import type { MealDish } from "../client";
3+import type { MealDishBody } from "./postMealDish";
4+
5+export function patchMealDishById(id: string, body: Partial<MealDishBody>): Promise<MealDish> {
6+ return client<MealDish>(`/meals/dishes/${encodeURIComponent(id)}`, { method: "PATCH", body });
7+}
src/api/meals/patchMealMenuById.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealMenu } from "../client";
3+
4+export function patchMealMenuById(id: string, body: { capacity?: number | null }): Promise<MealMenu> {
5+ return client<MealMenu>(`/meals/menus/${encodeURIComponent(id)}`, { method: "PATCH", body });
6+}
src/api/meals/postMealAttendance.tsadded+9 -0
@@ -0,0 +1,9 @@
1+import { client } from "../client";
2+import type { MealAttendance } from "../client";
3+
4+export function postMealAttendance(menuId: string, studentId: string, status: string): Promise<MealAttendance> {
5+ return client<MealAttendance>(`/meals/menus/${encodeURIComponent(menuId)}/attendance`, {
6+ method: "POST",
7+ body: { student_id: studentId, status },
8+ });
9+}
src/api/meals/postMealBooking.tsadded+9 -0
@@ -0,0 +1,9 @@
1+import { client } from "../client";
2+import type { MealBooking } from "../client";
3+
4+export function postMealBooking(menuId: string, studentId?: string): Promise<MealBooking> {
5+ return client<MealBooking>(`/meals/menus/${encodeURIComponent(menuId)}/bookings`, {
6+ method: "POST",
7+ body: studentId ? { student_id: studentId } : {},
8+ });
9+}
src/api/meals/postMealCredit.tsadded+11 -0
@@ -0,0 +1,11 @@
1+import { client } from "../client";
2+import type { MealLedgerEntry } from "../client";
3+
4+export function postMealCredit(body: {
5+ student_id: string;
6+ amount_minor: number;
7+ method?: string;
8+ note?: string;
9+}): Promise<MealLedgerEntry> {
10+ return client<MealLedgerEntry>("/meals/credits", { method: "POST", body });
11+}
src/api/meals/postMealDish.tsadded+8 -0
@@ -0,0 +1,8 @@
1+import { client } from "../client";
2+import type { MealDish } from "../client";
3+
4+export type MealDishBody = { name: string; description?: string | null; price_minor: number; tags: string[] };
5+
6+export function postMealDish(menuId: string, body: MealDishBody): Promise<MealDish> {
7+ return client<MealDish>(`/meals/menus/${encodeURIComponent(menuId)}/dishes`, { method: "POST", body });
8+}
src/api/meals/postMealMenu.tsadded+6 -0
@@ -0,0 +1,6 @@
1+import { client } from "../client";
2+import type { MealMenu } from "../client";
3+
4+export function postMealMenu(body: { date: string; slot: string; capacity?: number | null }): Promise<MealMenu> {
5+ return client<MealMenu>("/meals/menus", { method: "POST", body });
6+}
src/api/reports/getMyCourses.tsmodified+4 -3
@@ -1,8 +1,9 @@
1 import { client } from "../client";1 import { client } from "../client";
2-import { normalizePage, pageQuery, type Page, type PageParams } from "../client";2+import { normalizePage, type Page } from "../client";
3 import type { Course } from "../client";3 import type { Course } from "../client";
4+import { courseListQuery, type CourseListParams } from "../courses/getCourses";
4 5
5-export async function getMyCourses(params?: PageParams, signal?: AbortSignal): Promise<Page<Course>> {6+export async function getMyCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> {
6- const data = await client<unknown>(`/courses/me${pageQuery(params)}`, { signal });7+ const data = await client<unknown>(`/courses/me${courseListQuery(params)}`, { signal });
7 return normalizePage<Course>(data);8 return normalizePage<Course>(data);
8 }9 }
src/api/settings/patchSettings.tsmodified+7 -1
@@ -1,12 +1,18 @@
1 import { client } from "../client";1 import { client } from "../client";
2 import { setCachedSettings } from "./getSettings";2 import { setCachedSettings } from "./getSettings";
3-import type { ExamKindSetting, GradeBand, SchoolSettings } from "../client";3+import type { ExamKindSetting, GradeBand, MealSlot, SchoolSettings } from "../client";
4 4
5 export type PatchSettingsBody = {5 export type PatchSettingsBody = {
6 exam_kinds?: ExamKindSetting[];6 exam_kinds?: ExamKindSetting[];
7 attendance_statuses?: string[];7 attendance_statuses?: string[];
8 grade_bands?: GradeBand[];8 grade_bands?: GradeBand[];
9 max_file_bytes?: number;9 max_file_bytes?: number;
10+ chatbot_history_turns?: number;
11+ max_chatbot_threads?: number;
12+ max_chatbot_message_len?: number;
13+ meal_slots?: MealSlot[];
14+ dietary_tags?: string[];
15+ meal_cancel_cutoff_minutes?: number | null;
10 };16 };
11 17
12 export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> {18 export function patchSettings(body: PatchSettingsBody): Promise<SchoolSettings> {
src/pages/login-page.tsxmodified+10 -7
@@ -1,6 +1,7 @@
1 import { Link, useNavigate } from "@tanstack/solid-router";1 import { Link, useNavigate } from "@tanstack/solid-router";
2-import { createSignal, Show } from "solid-js";2+import { createResource, createSignal, Show } from "solid-js";
3 import { postLogin } from "@/api/auth";3 import { postLogin } from "@/api/auth";
4+import { getLimits } from "@/api/limits";
4 import { formatApiError } from "@/api/client";5 import { formatApiError } from "@/api/client";
5 import { Button } from "@/components/ui/button";6 import { Button } from "@/components/ui/button";
6 import { Input } from "@/components/ui/input";7 import { Input } from "@/components/ui/input";
@@ -27,16 +28,18 @@ function LoginForm() {
27 const [showPassword, setShowPassword] = createSignal(false);28 const [showPassword, setShowPassword] = createSignal(false);
28 const [error, setError] = createSignal("");29 const [error, setError] = createSignal("");
29 const [pending, setPending] = createSignal(false);30 const [pending, setPending] = createSignal(false);
31+ const [limits] = createResource(() => getLimits().catch(() => null));
30 32
31 const handleSubmit = async (e: SubmitEvent) => {33 const handleSubmit = async (e: SubmitEvent) => {
32 e.preventDefault();34 e.preventDefault();
33 const u = username().trim();35 const u = username().trim();
34 const p = password();36 const p = password();
35- if (u.length < 3 || u.length > 32) {37+ const userLimits = limits()?.user;
38+ if (userLimits && (u.length < userLimits.min_username_len || u.length > userLimits.max_username_len)) {
36 setError(t("auth.usernameHint"));39 setError(t("auth.usernameHint"));
37 return;40 return;
38 }41 }
39- if (p.length < 6 || p.length > 128) {42+ if (userLimits && (p.length < userLimits.min_password_len || p.length > userLimits.max_password_len)) {
40 setError(t("auth.passwordHint"));43 setError(t("auth.passwordHint"));
41 return;44 return;
42 }45 }
@@ -68,8 +71,8 @@ function LoginForm() {
68 id="login-username"71 id="login-username"
69 class="h-11"72 class="h-11"
70 autocomplete="username"73 autocomplete="username"
71- minlength={3}74+ minlength={limits()?.user.min_username_len}
72- maxlength={32}75+ maxlength={limits()?.user.max_username_len}
73 required76 required
74 value={username()}77 value={username()}
75 onInput={(e) => setUsername(e.currentTarget.value)}78 onInput={(e) => setUsername(e.currentTarget.value)}
@@ -84,8 +87,8 @@ function LoginForm() {
84 class="h-11 pr-10"87 class="h-11 pr-10"
85 type={showPassword() ? "text" : "password"}88 type={showPassword() ? "text" : "password"}
86 autocomplete="current-password"89 autocomplete="current-password"
87- minlength={6}90+ minlength={limits()?.user.min_password_len}
88- maxlength={128}91+ maxlength={limits()?.user.max_password_len}
89 required92 required
90 value={password()}93 value={password()}
91 onInput={(e) => setPassword(e.currentTarget.value)}94 onInput={(e) => setPassword(e.currentTarget.value)}
src/pages/register-page.tsxmodified+12 -9
@@ -1,6 +1,7 @@
1 import { Link, useNavigate } from "@tanstack/solid-router";1 import { Link, useNavigate } from "@tanstack/solid-router";
2-import { createSignal, Show } from "solid-js";2+import { createResource, createSignal, Show } from "solid-js";
3 import { postRegister } from "@/api/auth";3 import { postRegister } from "@/api/auth";
4+import { getLimits } from "@/api/limits";
4 import { formatApiError } from "@/api/client";5 import { formatApiError } from "@/api/client";
5 import { Button } from "@/components/ui/button";6 import { Button } from "@/components/ui/button";
6 import { Input } from "@/components/ui/input";7 import { Input } from "@/components/ui/input";
@@ -26,17 +27,19 @@ function RegisterForm() {
26 const [showPassword, setShowPassword] = createSignal(false);27 const [showPassword, setShowPassword] = createSignal(false);
27 const [error, setError] = createSignal("");28 const [error, setError] = createSignal("");
28 const [pending, setPending] = createSignal(false);29 const [pending, setPending] = createSignal(false);
30+ const [limits] = createResource(() => getLimits().catch(() => null));
29 31
30 const handleSubmit = async (e: SubmitEvent) => {32 const handleSubmit = async (e: SubmitEvent) => {
31 e.preventDefault();33 e.preventDefault();
32 const u = username().trim();34 const u = username().trim();
33 const p = password();35 const p = password();
34 const cp = confirmPassword();36 const cp = confirmPassword();
35- if (u.length < 3 || u.length > 32) {37+ const userLimits = limits()?.user;
38+ if (userLimits && (u.length < userLimits.min_username_len || u.length > userLimits.max_username_len)) {
36 setError(t("auth.usernameHint"));39 setError(t("auth.usernameHint"));
37 return;40 return;
38 }41 }
39- if (p.length < 6 || p.length > 128) {42+ if (userLimits && (p.length < userLimits.min_password_len || p.length > userLimits.max_password_len)) {
40 setError(t("auth.passwordHint"));43 setError(t("auth.passwordHint"));
41 return;44 return;
42 }45 }
@@ -71,8 +74,8 @@ function RegisterForm() {
71 id="register-username"74 id="register-username"
72 class="h-11"75 class="h-11"
73 autocomplete="username"76 autocomplete="username"
74- minlength={3}77+ minlength={limits()?.user.min_username_len}
75- maxlength={32}78+ maxlength={limits()?.user.max_username_len}
76 required79 required
77 value={username()}80 value={username()}
78 onInput={(e) => setUsername(e.currentTarget.value)}81 onInput={(e) => setUsername(e.currentTarget.value)}
@@ -87,8 +90,8 @@ function RegisterForm() {
87 class="h-11 pr-10"90 class="h-11 pr-10"
88 type={showPassword() ? "text" : "password"}91 type={showPassword() ? "text" : "password"}
89 autocomplete="new-password"92 autocomplete="new-password"
90- minlength={6}93+ minlength={limits()?.user.min_password_len}
91- maxlength={128}94+ maxlength={limits()?.user.max_password_len}
92 required95 required
93 value={password()}96 value={password()}
94 onInput={(e) => setPassword(e.currentTarget.value)}97 onInput={(e) => setPassword(e.currentTarget.value)}
@@ -113,8 +116,8 @@ function RegisterForm() {
113 class="h-11"116 class="h-11"
114 type={showPassword() ? "text" : "password"}117 type={showPassword() ? "text" : "password"}
115 autocomplete="new-password"118 autocomplete="new-password"
116- minlength={6}119+ minlength={limits()?.user.min_password_len}
117- maxlength={128}120+ maxlength={limits()?.user.max_password_len}
118 required121 required
119 value={confirmPassword()}122 value={confirmPassword()}
120 onInput={(e) => setConfirmPassword(e.currentTarget.value)}123 onInput={(e) => setConfirmPassword(e.currentTarget.value)}