🧩 API layer for grade templates, section overrides and holidays
Browse files at this commitf409644752e5403e5395a087c67d69e4986b55e4Parent: 167d960- feat
- 🧩 API layer for grade templates, section overrides and holidays
43 changed files +662 -13
- src/api/__tests__/contract/bank-questions.contract.test.ts +1 -1
- src/api/__tests__/contract/learning.contract.test.ts +1 -1
- src/api/__tests__/holidays/holidays.test.ts +65 -0
- src/api/__tests__/instances/instances.test.ts +133 -1
- src/api/__tests__/offerings/offerings.test.ts +141 -0
- src/api/holidays/deleteHolidayById.ts +6 -0
- src/api/holidays/getHolidayById.ts +6 -0
- src/api/holidays/getHolidays.ts +17 -0
- src/api/holidays/index.ts +5 -0
- src/api/holidays/patchHolidayById.ts +9 -0
- src/api/holidays/postHoliday.ts +10 -0
- src/api/instances/deleteInstanceExamWeightByKind.ts +6 -0
- src/api/instances/deleteInstanceExamWeights.ts +6 -0
- src/api/instances/deleteInstanceSubjectById.ts +6 -0
- src/api/instances/deleteInstanceSubjects.ts +6 -0
- src/api/instances/deleteInstanceWeeklyPlan.ts +6 -0
- src/api/instances/deleteInstanceWeeklySlotById.ts +6 -0
- src/api/instances/getInstanceExamWeights.ts +8 -0
- src/api/instances/getInstanceSubjects.ts +8 -0
- src/api/instances/getInstanceWeeklyPlan.ts +8 -0
- src/api/instances/index.ts +14 -0
- src/api/instances/patchInstanceById.ts +6 -1
- src/api/instances/patchInstanceExamWeight.ts +9 -0
- src/api/instances/postInstanceReset.ts +8 -0
- src/api/instances/postInstanceSubject.ts +8 -0
- src/api/instances/postInstanceWeeklyPlanMaterialize.ts +11 -0
- src/api/instances/postInstanceWeeklySlot.ts +8 -0
- src/api/offerings/deleteOfferingById.ts +6 -0
- src/api/offerings/deleteOfferingExamWeightByKind.ts +6 -0
- src/api/offerings/deleteOfferingSubjectById.ts +5 -0
- src/api/offerings/deleteOfferingWeeklySlotById.ts +5 -0
- src/api/offerings/getOfferingById.ts +7 -0
- src/api/offerings/getOfferingExamWeights.ts +6 -0
- src/api/offerings/getOfferingSubjects.ts +7 -0
- src/api/offerings/getOfferingWeeklyPlan.ts +7 -0
- src/api/offerings/getOfferings.ts +15 -0
- src/api/offerings/index.ts +14 -0
- src/api/offerings/patchOfferingById.ts +15 -0
- src/api/offerings/patchOfferingExamWeight.ts +8 -0
- src/api/offerings/postOffering.ts +17 -0
- src/api/offerings/postOfferingSubject.ts +7 -0
- src/api/offerings/postOfferingWeeklySlot.ts +10 -0
- src/lib/student-directory.test.ts +9 -9
src/api/__tests__/contract/bank-questions.contract.test.tsmodified+1 -1
| @@ -32,7 +32,7 @@ describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { | ||
| 32 | 32 | // `class` is the row, and `skipped` is the pair report (empty here). |
| 33 | 33 | const created = await json<{ class: { id: string }; skipped: unknown[] }>("/classes", { |
| 34 | 34 | method: "POST", |
| 35 | - body: { name: tag, grade: "9", year: yearId }, | |
| 35 | + body: { name: tag, grade_level: 9, year: yearId }, | |
| 36 | 36 | }); |
| 37 | 37 | classId = created.class.id; |
| 38 | 38 | expect(Array.isArray(created.skipped)).toBe(true); |
src/api/__tests__/contract/learning.contract.test.tsmodified+1 -1
| @@ -34,7 +34,7 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { | ||
| 34 | 34 | // `class` is the row, and `skipped` is the pair report (empty here). |
| 35 | 35 | const created = await json<{ class: { id: string }; skipped: unknown[] }>("/classes", { |
| 36 | 36 | method: "POST", |
| 37 | - body: { name: tag, grade: "9", year: yearId }, | |
| 37 | + body: { name: tag, grade_level: 9, year: yearId }, | |
| 38 | 38 | }); |
| 39 | 39 | classId = created.class.id; |
| 40 | 40 | expect(Array.isArray(created.skipped)).toBe(true); |
src/api/__tests__/holidays/holidays.test.tsadded+65 -0
| @@ -0,0 +1,65 @@ | ||
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; | |
| 2 | +import { | |
| 3 | + deleteHolidayById, | |
| 4 | + getHolidayById, | |
| 5 | + getHolidays, | |
| 6 | + patchHolidayById, | |
| 7 | + postHoliday, | |
| 8 | +} from "../../holidays"; | |
| 9 | +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | |
| 10 | + | |
| 11 | +describe("holidays API", () => { | |
| 12 | + afterEach(() => { | |
| 13 | + vi.restoreAllMocks(); | |
| 14 | + }); | |
| 15 | + | |
| 16 | + it("getHolidays GETs /holidays with paging and the overlap window", async () => { | |
| 17 | + mockFetchSuccess({ items: [], total: 0 }); | |
| 18 | + await getHolidays({ limit: 50, offset: 0, from: 1000, to: 2000 }); | |
| 19 | + const [url, init] = lastFetchCall(); | |
| 20 | + expect(url).toBe("/api/holidays?limit=50&offset=0&from=1000&to=2000"); | |
| 21 | + expect(init?.method).toBe("GET"); | |
| 22 | + }); | |
| 23 | + | |
| 24 | + it("getHolidays sends no query when unfiltered", async () => { | |
| 25 | + mockFetchSuccess({ items: [], total: 0 }); | |
| 26 | + await getHolidays(); | |
| 27 | + const [url, init] = lastFetchCall(); | |
| 28 | + expect(url).toBe("/api/holidays"); | |
| 29 | + expect(init?.method).toBe("GET"); | |
| 30 | + }); | |
| 31 | + | |
| 32 | + it("getHolidayById GETs /holidays/h1", async () => { | |
| 33 | + mockFetchSuccess({ id: "x1" }); | |
| 34 | + await getHolidayById("h1"); | |
| 35 | + const [url, init] = lastFetchCall(); | |
| 36 | + expect(url).toBe("/api/holidays/h1"); | |
| 37 | + expect(init?.method).toBe("GET"); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + it("postHoliday POSTs /holidays", async () => { | |
| 41 | + mockFetchSuccess({ id: "x1" }); | |
| 42 | + await postHoliday({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 }); | |
| 43 | + const [url, init] = lastFetchCall(); | |
| 44 | + expect(url).toBe("/api/holidays"); | |
| 45 | + expect(init?.method).toBe("POST"); | |
| 46 | + expect(init?.body).toBe(JSON.stringify({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 })); | |
| 47 | + }); | |
| 48 | + | |
| 49 | + it("patchHolidayById PATCHs /holidays/h1", async () => { | |
| 50 | + mockFetchSuccess({ id: "x1" }); | |
| 51 | + await patchHolidayById("h1", { name: "Ara tatil" }); | |
| 52 | + const [url, init] = lastFetchCall(); | |
| 53 | + expect(url).toBe("/api/holidays/h1"); | |
| 54 | + expect(init?.method).toBe("PATCH"); | |
| 55 | + expect(init?.body).toBe(JSON.stringify({ name: "Ara tatil" })); | |
| 56 | + }); | |
| 57 | + | |
| 58 | + it("deleteHolidayById DELETEs /holidays/h1", async () => { | |
| 59 | + mockFetch204(); | |
| 60 | + await deleteHolidayById("h1"); | |
| 61 | + const [url, init] = lastFetchCall(); | |
| 62 | + expect(url).toBe("/api/holidays/h1"); | |
| 63 | + expect(init?.method).toBe("DELETE"); | |
| 64 | + }); | |
| 65 | +}); |
src/api/__tests__/instances/instances.test.tsmodified+133 -1
| @@ -14,6 +14,20 @@ import { | ||
| 14 | 14 | postInstanceHomework, |
| 15 | 15 | postInstanceSession, |
| 16 | 16 | postInstanceTeacher, |
| 17 | + deleteInstanceExamWeightByKind, | |
| 18 | + deleteInstanceExamWeights, | |
| 19 | + deleteInstanceSubjectById, | |
| 20 | + deleteInstanceSubjects, | |
| 21 | + deleteInstanceWeeklyPlan, | |
| 22 | + deleteInstanceWeeklySlotById, | |
| 23 | + getInstanceExamWeights, | |
| 24 | + getInstanceSubjects, | |
| 25 | + getInstanceWeeklyPlan, | |
| 26 | + patchInstanceExamWeight, | |
| 27 | + postInstanceReset, | |
| 28 | + postInstanceSubject, | |
| 29 | + postInstanceWeeklyPlanMaterialize, | |
| 30 | + postInstanceWeeklySlot, | |
| 17 | 31 | } from "../../instances"; |
| 18 | 32 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 19 | 33 | |
| @@ -45,7 +59,7 @@ describe("instances API", () => { | ||
| 45 | 59 | |
| 46 | 60 | it("patchInstanceById PATCHes /instances/:id with the policy body", async () => { |
| 47 | 61 | mockFetchSuccess({ id: "i1" }); |
| 48 | - const body = { ders_saati: 4, counts_toward_karne: false }; | |
| 62 | + const body = { title: "9-A Matematik", description: "Sayısal", ders_saati: 4, counts_toward_karne: false }; | |
| 49 | 63 | |
| 50 | 64 | await patchInstanceById("i1", body); |
| 51 | 65 | |
| @@ -168,4 +182,122 @@ describe("instances API", () => { | ||
| 168 | 182 | expect(url).toBe("/api/instances/i1/teachers/t1"); |
| 169 | 183 | expect(init?.method).toBe("DELETE"); |
| 170 | 184 | }); |
| 185 | + | |
| 186 | + // Per-section overrides over the grade-level offering. | |
| 187 | + it("postInstanceReset POSTs /instances/i1/reset", async () => { | |
| 188 | + mockFetchSuccess({ id: "x1" }); | |
| 189 | + await postInstanceReset("i1", ["title", "weekly_plan"]); | |
| 190 | + const [url, init] = lastFetchCall(); | |
| 191 | + expect(url).toBe("/api/instances/i1/reset"); | |
| 192 | + expect(init?.method).toBe("POST"); | |
| 193 | + expect(init?.body).toBe(JSON.stringify({ fields: ["title", "weekly_plan"] })); | |
| 194 | + }); | |
| 195 | + | |
| 196 | + it("getInstanceSubjects GETs /instances/i1/subjects", async () => { | |
| 197 | + mockFetchSuccess({ subjects: [], subjects_inherited: true }); | |
| 198 | + await getInstanceSubjects("i1"); | |
| 199 | + const [url, init] = lastFetchCall(); | |
| 200 | + expect(url).toBe("/api/instances/i1/subjects"); | |
| 201 | + expect(init?.method).toBe("GET"); | |
| 202 | + }); | |
| 203 | + | |
| 204 | + it("postInstanceSubject POSTs /instances/i1/subjects", async () => { | |
| 205 | + mockFetchSuccess({ id: "x1" }); | |
| 206 | + await postInstanceSubject("i1", "s1"); | |
| 207 | + const [url, init] = lastFetchCall(); | |
| 208 | + expect(url).toBe("/api/instances/i1/subjects"); | |
| 209 | + expect(init?.method).toBe("POST"); | |
| 210 | + expect(init?.body).toBe(JSON.stringify({ subject: "s1" })); | |
| 211 | + }); | |
| 212 | + | |
| 213 | + it("deleteInstanceSubjects DELETEs /instances/i1/subjects", async () => { | |
| 214 | + mockFetch204(); | |
| 215 | + await deleteInstanceSubjects("i1"); | |
| 216 | + const [url, init] = lastFetchCall(); | |
| 217 | + expect(url).toBe("/api/instances/i1/subjects"); | |
| 218 | + expect(init?.method).toBe("DELETE"); | |
| 219 | + }); | |
| 220 | + | |
| 221 | + it("deleteInstanceSubjectById DELETEs /instances/i1/subjects/s1", async () => { | |
| 222 | + mockFetch204(); | |
| 223 | + await deleteInstanceSubjectById("i1", "s1"); | |
| 224 | + const [url, init] = lastFetchCall(); | |
| 225 | + expect(url).toBe("/api/instances/i1/subjects/s1"); | |
| 226 | + expect(init?.method).toBe("DELETE"); | |
| 227 | + }); | |
| 228 | + | |
| 229 | + it("getInstanceWeeklyPlan GETs /instances/i1/weekly-plan", async () => { | |
| 230 | + mockFetchSuccess({ weekly_plan: [], weekly_plan_inherited: true }); | |
| 231 | + await getInstanceWeeklyPlan("i1"); | |
| 232 | + const [url, init] = lastFetchCall(); | |
| 233 | + expect(url).toBe("/api/instances/i1/weekly-plan"); | |
| 234 | + expect(init?.method).toBe("GET"); | |
| 235 | + }); | |
| 236 | + | |
| 237 | + it("postInstanceWeeklySlot POSTs /instances/i1/weekly-plan", async () => { | |
| 238 | + mockFetchSuccess({ id: "x1" }); | |
| 239 | + await postInstanceWeeklySlot("i1", { weekday: 3, starts_at: 600, ends_at: 640 }); | |
| 240 | + const [url, init] = lastFetchCall(); | |
| 241 | + expect(url).toBe("/api/instances/i1/weekly-plan"); | |
| 242 | + expect(init?.method).toBe("POST"); | |
| 243 | + expect(init?.body).toBe(JSON.stringify({ weekday: 3, starts_at: 600, ends_at: 640 })); | |
| 244 | + }); | |
| 245 | + | |
| 246 | + it("deleteInstanceWeeklyPlan DELETEs /instances/i1/weekly-plan", async () => { | |
| 247 | + mockFetch204(); | |
| 248 | + await deleteInstanceWeeklyPlan("i1"); | |
| 249 | + const [url, init] = lastFetchCall(); | |
| 250 | + expect(url).toBe("/api/instances/i1/weekly-plan"); | |
| 251 | + expect(init?.method).toBe("DELETE"); | |
| 252 | + }); | |
| 253 | + | |
| 254 | + it("deleteInstanceWeeklySlotById DELETEs /instances/i1/weekly-plan/sl1", async () => { | |
| 255 | + mockFetch204(); | |
| 256 | + await deleteInstanceWeeklySlotById("i1", "sl1"); | |
| 257 | + const [url, init] = lastFetchCall(); | |
| 258 | + expect(url).toBe("/api/instances/i1/weekly-plan/sl1"); | |
| 259 | + expect(init?.method).toBe("DELETE"); | |
| 260 | + }); | |
| 261 | + | |
| 262 | + it("postInstanceWeeklyPlanMaterialize POSTs the range as a dry run", async () => { | |
| 263 | + mockFetchSuccess({ applied: false, created: [] }); | |
| 264 | + await postInstanceWeeklyPlanMaterialize("i1", { from: 10, to: 20, apply: false }); | |
| 265 | + const [url, init] = lastFetchCall(); | |
| 266 | + expect(url).toBe("/api/instances/i1/weekly-plan/materialize"); | |
| 267 | + expect(init?.method).toBe("POST"); | |
| 268 | + expect(init?.body).toBe(JSON.stringify({ from: 10, to: 20, apply: false })); | |
| 269 | + }); | |
| 270 | + | |
| 271 | + it("getInstanceExamWeights GETs /instances/i1/exam-weights", async () => { | |
| 272 | + mockFetchSuccess({ inherited: true, weights: [] }); | |
| 273 | + await getInstanceExamWeights("i1"); | |
| 274 | + const [url, init] = lastFetchCall(); | |
| 275 | + expect(url).toBe("/api/instances/i1/exam-weights"); | |
| 276 | + expect(init?.method).toBe("GET"); | |
| 277 | + }); | |
| 278 | + | |
| 279 | + it("patchInstanceExamWeight PATCHs /instances/i1/exam-weights", async () => { | |
| 280 | + mockFetchSuccess({ inherited: false, weights: [] }); | |
| 281 | + await patchInstanceExamWeight("i1", { kind: "quiz", weight: 10 }); | |
| 282 | + const [url, init] = lastFetchCall(); | |
| 283 | + expect(url).toBe("/api/instances/i1/exam-weights"); | |
| 284 | + expect(init?.method).toBe("PATCH"); | |
| 285 | + expect(init?.body).toBe(JSON.stringify({ kind: "quiz", weight: 10 })); | |
| 286 | + }); | |
| 287 | + | |
| 288 | + it("deleteInstanceExamWeights DELETEs /instances/i1/exam-weights", async () => { | |
| 289 | + mockFetch204(); | |
| 290 | + await deleteInstanceExamWeights("i1"); | |
| 291 | + const [url, init] = lastFetchCall(); | |
| 292 | + expect(url).toBe("/api/instances/i1/exam-weights"); | |
| 293 | + expect(init?.method).toBe("DELETE"); | |
| 294 | + }); | |
| 295 | + | |
| 296 | + it("deleteInstanceExamWeightByKind DELETEs /instances/i1/exam-weights/quiz", async () => { | |
| 297 | + mockFetch204(); | |
| 298 | + await deleteInstanceExamWeightByKind("i1", "quiz"); | |
| 299 | + const [url, init] = lastFetchCall(); | |
| 300 | + expect(url).toBe("/api/instances/i1/exam-weights/quiz"); | |
| 301 | + expect(init?.method).toBe("DELETE"); | |
| 302 | + }); | |
| 171 | 303 | }); |
src/api/__tests__/offerings/offerings.test.tsadded+141 -0
| @@ -0,0 +1,141 @@ | ||
| 1 | +import { afterEach, describe, expect, it, vi } from "vitest"; | |
| 2 | +import { | |
| 3 | + deleteOfferingById, | |
| 4 | + deleteOfferingExamWeightByKind, | |
| 5 | + deleteOfferingSubjectById, | |
| 6 | + deleteOfferingWeeklySlotById, | |
| 7 | + getOfferingById, | |
| 8 | + getOfferingExamWeights, | |
| 9 | + getOfferingSubjects, | |
| 10 | + getOfferingWeeklyPlan, | |
| 11 | + getOfferings, | |
| 12 | + patchOfferingById, | |
| 13 | + patchOfferingExamWeight, | |
| 14 | + postOffering, | |
| 15 | + postOfferingSubject, | |
| 16 | + postOfferingWeeklySlot, | |
| 17 | +} from "../../offerings"; | |
| 18 | +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; | |
| 19 | + | |
| 20 | +describe("offerings API", () => { | |
| 21 | + afterEach(() => { | |
| 22 | + vi.restoreAllMocks(); | |
| 23 | + }); | |
| 24 | + | |
| 25 | + it("getOfferings GETs /offerings narrowed by course and grade level (0 included)", async () => { | |
| 26 | + mockFetchSuccess({ items: [], total: 0 }); | |
| 27 | + await getOfferings({ course: "co1", grade_level: 0, limit: 20 }); | |
| 28 | + const [url, init] = lastFetchCall(); | |
| 29 | + expect(url).toBe("/api/offerings?limit=20&course=co1&grade_level=0"); | |
| 30 | + expect(init?.method).toBe("GET"); | |
| 31 | + }); | |
| 32 | + | |
| 33 | + it("getOfferingById GETs /offerings/o1", async () => { | |
| 34 | + mockFetchSuccess({ id: "x1" }); | |
| 35 | + await getOfferingById("o1"); | |
| 36 | + const [url, init] = lastFetchCall(); | |
| 37 | + expect(url).toBe("/api/offerings/o1"); | |
| 38 | + expect(init?.method).toBe("GET"); | |
| 39 | + }); | |
| 40 | + | |
| 41 | + it("postOffering POSTs /offerings", async () => { | |
| 42 | + mockFetchSuccess({ id: "x1" }); | |
| 43 | + await postOffering({ course: "co1", grade_level: 9, default_ders_saati: 4 }); | |
| 44 | + const [url, init] = lastFetchCall(); | |
| 45 | + expect(url).toBe("/api/offerings"); | |
| 46 | + expect(init?.method).toBe("POST"); | |
| 47 | + expect(init?.body).toBe(JSON.stringify({ course: "co1", grade_level: 9, default_ders_saati: 4 })); | |
| 48 | + }); | |
| 49 | + | |
| 50 | + it("patchOfferingById PATCHes /offerings/o1 and sends null to clear back to inherit", async () => { | |
| 51 | + mockFetchSuccess({ id: "x1" }); | |
| 52 | + await patchOfferingById("o1", { title: null, default_counts_toward_karne: false }); | |
| 53 | + const [url, init] = lastFetchCall(); | |
| 54 | + expect(url).toBe("/api/offerings/o1"); | |
| 55 | + expect(init?.method).toBe("PATCH"); | |
| 56 | + expect(init?.body).toBe(JSON.stringify({ title: null, default_counts_toward_karne: false })); | |
| 57 | + }); | |
| 58 | + | |
| 59 | + it("deleteOfferingById DELETEs /offerings/o1", async () => { | |
| 60 | + mockFetch204(); | |
| 61 | + await deleteOfferingById("o1"); | |
| 62 | + const [url, init] = lastFetchCall(); | |
| 63 | + expect(url).toBe("/api/offerings/o1"); | |
| 64 | + expect(init?.method).toBe("DELETE"); | |
| 65 | + }); | |
| 66 | + | |
| 67 | + it("getOfferingSubjects GETs /offerings/o1/subjects", async () => { | |
| 68 | + mockFetchSuccess([]); | |
| 69 | + await getOfferingSubjects("o1"); | |
| 70 | + const [url, init] = lastFetchCall(); | |
| 71 | + expect(url).toBe("/api/offerings/o1/subjects"); | |
| 72 | + expect(init?.method).toBe("GET"); | |
| 73 | + }); | |
| 74 | + | |
| 75 | + it("postOfferingSubject POSTs /offerings/o1/subjects", async () => { | |
| 76 | + mockFetchSuccess({ id: "x1" }); | |
| 77 | + await postOfferingSubject("o1", "s1"); | |
| 78 | + const [url, init] = lastFetchCall(); | |
| 79 | + expect(url).toBe("/api/offerings/o1/subjects"); | |
| 80 | + expect(init?.method).toBe("POST"); | |
| 81 | + expect(init?.body).toBe(JSON.stringify({ subject: "s1" })); | |
| 82 | + }); | |
| 83 | + | |
| 84 | + it("deleteOfferingSubjectById DELETEs /offerings/o1/subjects/s1", async () => { | |
| 85 | + mockFetch204(); | |
| 86 | + await deleteOfferingSubjectById("o1", "s1"); | |
| 87 | + const [url, init] = lastFetchCall(); | |
| 88 | + expect(url).toBe("/api/offerings/o1/subjects/s1"); | |
| 89 | + expect(init?.method).toBe("DELETE"); | |
| 90 | + }); | |
| 91 | + | |
| 92 | + it("getOfferingWeeklyPlan GETs /offerings/o1/weekly-plan", async () => { | |
| 93 | + mockFetchSuccess([]); | |
| 94 | + await getOfferingWeeklyPlan("o1"); | |
| 95 | + const [url, init] = lastFetchCall(); | |
| 96 | + expect(url).toBe("/api/offerings/o1/weekly-plan"); | |
| 97 | + expect(init?.method).toBe("GET"); | |
| 98 | + }); | |
| 99 | + | |
| 100 | + it("postOfferingWeeklySlot POSTs /offerings/o1/weekly-plan", async () => { | |
| 101 | + mockFetchSuccess({ id: "x1" }); | |
| 102 | + await postOfferingWeeklySlot("o1", { weekday: 1, starts_at: 540, ends_at: 580, topic: null }); | |
| 103 | + const [url, init] = lastFetchCall(); | |
| 104 | + expect(url).toBe("/api/offerings/o1/weekly-plan"); | |
| 105 | + expect(init?.method).toBe("POST"); | |
| 106 | + expect(init?.body).toBe(JSON.stringify({ weekday: 1, starts_at: 540, ends_at: 580, topic: null })); | |
| 107 | + }); | |
| 108 | + | |
| 109 | + it("deleteOfferingWeeklySlotById DELETEs /offerings/o1/weekly-plan/sl1", async () => { | |
| 110 | + mockFetch204(); | |
| 111 | + await deleteOfferingWeeklySlotById("o1", "sl1"); | |
| 112 | + const [url, init] = lastFetchCall(); | |
| 113 | + expect(url).toBe("/api/offerings/o1/weekly-plan/sl1"); | |
| 114 | + expect(init?.method).toBe("DELETE"); | |
| 115 | + }); | |
| 116 | + | |
| 117 | + it("getOfferingExamWeights GETs /offerings/o1/exam-weights", async () => { | |
| 118 | + mockFetchSuccess({ weights: [] }); | |
| 119 | + await getOfferingExamWeights("o1"); | |
| 120 | + const [url, init] = lastFetchCall(); | |
| 121 | + expect(url).toBe("/api/offerings/o1/exam-weights"); | |
| 122 | + expect(init?.method).toBe("GET"); | |
| 123 | + }); | |
| 124 | + | |
| 125 | + it("patchOfferingExamWeight PATCHs /offerings/o1/exam-weights", async () => { | |
| 126 | + mockFetchSuccess({ weights: [] }); | |
| 127 | + await patchOfferingExamWeight("o1", { kind: "midterm", weight: 40 }); | |
| 128 | + const [url, init] = lastFetchCall(); | |
| 129 | + expect(url).toBe("/api/offerings/o1/exam-weights"); | |
| 130 | + expect(init?.method).toBe("PATCH"); | |
| 131 | + expect(init?.body).toBe(JSON.stringify({ kind: "midterm", weight: 40 })); | |
| 132 | + }); | |
| 133 | + | |
| 134 | + it("deleteOfferingExamWeightByKind encodes the kind in the path", async () => { | |
| 135 | + mockFetch204(); | |
| 136 | + await deleteOfferingExamWeightByKind("o1", "ara sınav"); | |
| 137 | + const [url, init] = lastFetchCall(); | |
| 138 | + expect(url).toBe("/api/offerings/o1/exam-weights/ara%20s%C4%B1nav"); | |
| 139 | + expect(init?.method).toBe("DELETE"); | |
| 140 | + }); | |
| 141 | +}); |
src/api/holidays/deleteHolidayById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Manager+. Lessons already generated on those days stay where they are. | |
| 4 | +export function deleteHolidayById(id: string): Promise<void> { | |
| 5 | + return client<void>(`/holidays/${id}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/holidays/getHolidayById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Holiday } from "../client"; | |
| 3 | + | |
| 4 | +export function getHolidayById(id: string, signal?: AbortSignal): Promise<Holiday> { | |
| 5 | + return client<Holiday>(`/holidays/${id}`, { signal }); | |
| 6 | +} |
src/api/holidays/getHolidays.tsadded+17 -0
| @@ -0,0 +1,17 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; | |
| 3 | +import type { Holiday } from "../client"; | |
| 4 | + | |
| 5 | +/** `from`/`to` (UTC unix-millis) keep the holidays overlapping that window. */ | |
| 6 | +export type HolidayListParams = PageParams & { from?: number; to?: number }; | |
| 7 | + | |
| 8 | +// Any signed-in session reads the calendar; newest start first. | |
| 9 | +export async function getHolidays(params?: HolidayListParams, signal?: AbortSignal): Promise<Page<Holiday>> { | |
| 10 | + const query = new URLSearchParams(); | |
| 11 | + appendPageParams(query, params); | |
| 12 | + if (params?.from != null) query.set("from", String(params.from)); | |
| 13 | + if (params?.to != null) query.set("to", String(params.to)); | |
| 14 | + const value = query.toString(); | |
| 15 | + const data = await client<unknown>(`/holidays${value ? `?${value}` : ""}`, { signal }); | |
| 16 | + return normalizePage<Holiday>(data); | |
| 17 | +} |
src/api/holidays/index.tsadded+5 -0
| @@ -0,0 +1,5 @@ | ||
| 1 | +export * from "./getHolidays"; | |
| 2 | +export * from "./getHolidayById"; | |
| 3 | +export * from "./postHoliday"; | |
| 4 | +export * from "./patchHolidayById"; | |
| 5 | +export * from "./deleteHolidayById"; |
src/api/holidays/patchHolidayById.tsadded+9 -0
| @@ -0,0 +1,9 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Holiday } from "../client"; | |
| 3 | + | |
| 4 | +/** Omit a field to keep it; the merged range must stay ordered. */ | |
| 5 | +export type UpdateHolidayBody = Partial<{ name: string; kind: string; starts_at: number; ends_at: number }>; | |
| 6 | + | |
| 7 | +export function patchHolidayById(id: string, body: UpdateHolidayBody): Promise<Holiday> { | |
| 8 | + return client<Holiday>(`/holidays/${id}`, { method: "PATCH", body }); | |
| 9 | +} |
src/api/holidays/postHoliday.tsadded+10 -0
| @@ -0,0 +1,10 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Holiday } from "../client"; | |
| 3 | + | |
| 4 | +/** `starts_at`/`ends_at` are the first and last blocked instants, UTC unix-millis. */ | |
| 5 | +export type CreateHolidayBody = { name: string; kind: string; starts_at: number; ends_at: number }; | |
| 6 | + | |
| 7 | +// Manager+. Past ranges are allowed — the calendar is a record. | |
| 8 | +export function postHoliday(body: CreateHolidayBody): Promise<Holiday> { | |
| 9 | + return client<Holiday>("/holidays", { method: "POST", body }); | |
| 10 | +} |
src/api/instances/deleteInstanceExamWeightByKind.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Drops one kind's row; the map stays the section's own. | |
| 4 | +export function deleteInstanceExamWeightByKind(id: string, kind: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/exam-weights/${encodeURIComponent(kind)}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/deleteInstanceExamWeights.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Resets the weights to inherit (offering, then settings, then 1). | |
| 4 | +export function deleteInstanceExamWeights(id: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/exam-weights`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/deleteInstanceSubjectById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Drops one topic from the section's own set; the set stays the section's own. | |
| 4 | +export function deleteInstanceSubjectById(id: string, subjectId: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/subjects/${subjectId}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/deleteInstanceSubjects.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Restores inheritance: drops the section's own topics, the offering's apply. | |
| 4 | +export function deleteInstanceSubjects(id: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/subjects`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/deleteInstanceWeeklyPlan.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Resets the week to inherit: drops every own slot, the template applies again. | |
| 4 | +export function deleteInstanceWeeklyPlan(id: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/weekly-plan`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/deleteInstanceWeeklySlotById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Dropping the last own slot leaves an empty own plan, not a return to inherit. | |
| 4 | +export function deleteInstanceWeeklySlotById(id: string, slotId: string): Promise<void> { | |
| 5 | + return client<void>(`/instances/${id}/weekly-plan/${slotId}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/instances/getInstanceExamWeights.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { ExamWeightEntry } from "../client"; | |
| 3 | + | |
| 4 | +export type InstanceExamWeights = { inherited: boolean; weights: ExamWeightEntry[] }; | |
| 5 | + | |
| 6 | +export function getInstanceExamWeights(id: string, signal?: AbortSignal): Promise<InstanceExamWeights> { | |
| 7 | + return client<InstanceExamWeights>(`/instances/${id}/exam-weights`, { signal }); | |
| 8 | +} |
src/api/instances/getInstanceSubjects.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Subject } from "../client"; | |
| 3 | + | |
| 4 | +export type ResolvedSubjects = { subjects: Subject[]; subjects_inherited: boolean }; | |
| 5 | + | |
| 6 | +export function getInstanceSubjects(id: string, signal?: AbortSignal): Promise<ResolvedSubjects> { | |
| 7 | + return client<ResolvedSubjects>(`/instances/${id}/subjects`, { signal }); | |
| 8 | +} |
src/api/instances/getInstanceWeeklyPlan.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { WeeklySlot } from "../client"; | |
| 3 | + | |
| 4 | +export type InstanceWeeklyPlan = { weekly_plan: WeeklySlot[]; weekly_plan_inherited: boolean }; | |
| 5 | + | |
| 6 | +export function getInstanceWeeklyPlan(id: string, signal?: AbortSignal): Promise<InstanceWeeklyPlan> { | |
| 7 | + return client<InstanceWeeklyPlan>(`/instances/${id}/weekly-plan`, { signal }); | |
| 8 | +} |
src/api/instances/index.tsmodified+14 -0
| @@ -12,3 +12,17 @@ export * from "./getInstanceSessions"; | ||
| 12 | 12 | export * from "./postInstanceSession"; |
| 13 | 13 | export * from "./postInstanceTeacher"; |
| 14 | 14 | export * from "./deleteInstanceTeacherByUserId"; |
| 15 | +export * from "./postInstanceReset"; | |
| 16 | +export * from "./getInstanceSubjects"; | |
| 17 | +export * from "./postInstanceSubject"; | |
| 18 | +export * from "./deleteInstanceSubjects"; | |
| 19 | +export * from "./deleteInstanceSubjectById"; | |
| 20 | +export * from "./getInstanceWeeklyPlan"; | |
| 21 | +export * from "./postInstanceWeeklySlot"; | |
| 22 | +export * from "./deleteInstanceWeeklyPlan"; | |
| 23 | +export * from "./deleteInstanceWeeklySlotById"; | |
| 24 | +export * from "./postInstanceWeeklyPlanMaterialize"; | |
| 25 | +export * from "./getInstanceExamWeights"; | |
| 26 | +export * from "./patchInstanceExamWeight"; | |
| 27 | +export * from "./deleteInstanceExamWeights"; | |
| 28 | +export * from "./deleteInstanceExamWeightByKind"; |
src/api/instances/patchInstanceById.tsmodified+6 -1
| @@ -1,8 +1,13 @@ | ||
| 1 | 1 | import { client } from "../client"; |
| 2 | 2 | import type { Instance } from "../client"; |
| 3 | 3 | |
| 4 | -/** Both fields are non-clearable: omit to keep, never send null. */ | |
| 4 | +/** | |
| 5 | + * The section's own overrides. Omit to keep; a PATCH sets, it never clears — | |
| 6 | + * clearing back to inherit is postInstanceReset. Never send null. | |
| 7 | + */ | |
| 5 | 8 | export type PatchInstanceBody = { |
| 9 | + title?: string; | |
| 10 | + description?: string; | |
| 6 | 11 | ders_saati?: number; |
| 7 | 12 | counts_toward_karne?: boolean; |
| 8 | 13 | }; |
src/api/instances/patchInstanceExamWeight.tsadded+9 -0
| @@ -0,0 +1,9 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { ExamWeightEntry } from "../client"; | |
| 3 | +import type { InstanceExamWeights } from "./getInstanceExamWeights"; | |
| 4 | + | |
| 5 | +// Sets one kind's weight and takes the whole map own: kinds without a row | |
| 6 | +// then weigh 1 here instead of following the offering. | |
| 7 | +export function patchInstanceExamWeight(id: string, body: ExamWeightEntry): Promise<InstanceExamWeights> { | |
| 8 | + return client<InstanceExamWeights>(`/instances/${id}/exam-weights`, { method: "PATCH", body }); | |
| 9 | +} |
src/api/instances/postInstanceReset.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Instance, InstanceOverrideField } from "../client"; | |
| 3 | + | |
| 4 | +// Clears the named overrides back to inherit; a set field (subjects, | |
| 5 | +// exam_weights, weekly_plan) flips its flag back to inherited. | |
| 6 | +export function postInstanceReset(id: string, fields: InstanceOverrideField[]): Promise<Instance> { | |
| 7 | + return client<Instance>(`/instances/${id}/reset`, { method: "POST", body: { fields } }); | |
| 8 | +} |
src/api/instances/postInstanceSubject.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Subject } from "../client"; | |
| 3 | + | |
| 4 | +// Selects a topic for the section's own set — the set becomes the section's | |
| 5 | +// own (not the offering's) from this call on. | |
| 6 | +export function postInstanceSubject(id: string, subjectId: string): Promise<Subject> { | |
| 7 | + return client<Subject>(`/instances/${id}/subjects`, { method: "POST", body: { subject: subjectId } }); | |
| 8 | +} |
src/api/instances/postInstanceWeeklyPlanMaterialize.tsadded+11 -0
| @@ -0,0 +1,11 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { MaterializeReport } from "../client"; | |
| 3 | + | |
| 4 | +/** `from`/`to` are UTC unix-millis naming school days; `apply: false` is a dry run. */ | |
| 5 | +export type MaterializeBody = { from: number; to: number; apply?: boolean }; | |
| 6 | + | |
| 7 | +// Expands the resolved week into dated lessons. Additive and idempotent: | |
| 8 | +// holiday days and already-scheduled starts are skipped and counted. | |
| 9 | +export function postInstanceWeeklyPlanMaterialize(id: string, body: MaterializeBody): Promise<MaterializeReport> { | |
| 10 | + return client<MaterializeReport>(`/instances/${id}/weekly-plan/materialize`, { method: "POST", body }); | |
| 11 | +} |
src/api/instances/postInstanceWeeklySlot.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { WeeklySlot } from "../client"; | |
| 3 | +import type { CreateWeeklySlotBody } from "../offerings/postOfferingWeeklySlot"; | |
| 4 | + | |
| 5 | +// Adds a slot to the section's own week; from here its own rows are the plan. | |
| 6 | +export function postInstanceWeeklySlot(id: string, body: CreateWeeklySlotBody): Promise<WeeklySlot> { | |
| 7 | + return client<WeeklySlot>(`/instances/${id}/weekly-plan`, { method: "POST", body }); | |
| 8 | +} |
src/api/offerings/deleteOfferingById.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Manager+. A 409 `offering_in_use` while any section still teaches from it. | |
| 4 | +export function deleteOfferingById(id: string): Promise<void> { | |
| 5 | + return client<void>(`/offerings/${id}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/offerings/deleteOfferingExamWeightByKind.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +// Drops the template's row; the settings weight applies again. | |
| 4 | +export function deleteOfferingExamWeightByKind(id: string, kind: string): Promise<void> { | |
| 5 | + return client<void>(`/offerings/${id}/exam-weights/${encodeURIComponent(kind)}`, { method: "DELETE" }); | |
| 6 | +} |
src/api/offerings/deleteOfferingSubjectById.tsadded+5 -0
| @@ -0,0 +1,5 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +export function deleteOfferingSubjectById(id: string, subjectId: string): Promise<void> { | |
| 4 | + return client<void>(`/offerings/${id}/subjects/${subjectId}`, { method: "DELETE" }); | |
| 5 | +} |
src/api/offerings/deleteOfferingWeeklySlotById.tsadded+5 -0
| @@ -0,0 +1,5 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | + | |
| 3 | +export function deleteOfferingWeeklySlotById(id: string, slotId: string): Promise<void> { | |
| 4 | + return client<void>(`/offerings/${id}/weekly-plan/${slotId}`, { method: "DELETE" }); | |
| 5 | +} |
src/api/offerings/getOfferingById.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Offering } from "../client"; | |
| 3 | + | |
| 4 | +// The raw template row: a null field inherits, it is not the resolved value. | |
| 5 | +export function getOfferingById(id: string, signal?: AbortSignal): Promise<Offering> { | |
| 6 | + return client<Offering>(`/offerings/${id}`, { signal }); | |
| 7 | +} |
src/api/offerings/getOfferingExamWeights.tsadded+6 -0
| @@ -0,0 +1,6 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { ExamWeightEntry } from "../client"; | |
| 3 | + | |
| 4 | +export function getOfferingExamWeights(id: string, signal?: AbortSignal): Promise<{ weights: ExamWeightEntry[] }> { | |
| 5 | + return client<{ weights: ExamWeightEntry[] }>(`/offerings/${id}/exam-weights`, { signal }); | |
| 6 | +} |
src/api/offerings/getOfferingSubjects.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Subject } from "../client"; | |
| 3 | + | |
| 4 | +// The topics every inheriting section at this grade teaches. | |
| 5 | +export function getOfferingSubjects(id: string, signal?: AbortSignal): Promise<Subject[]> { | |
| 6 | + return client<Subject[]>(`/offerings/${id}/subjects`, { signal }); | |
| 7 | +} |
src/api/offerings/getOfferingWeeklyPlan.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { WeeklySlot } from "../client"; | |
| 3 | + | |
| 4 | +// The template week, weekday first, then start time. | |
| 5 | +export function getOfferingWeeklyPlan(id: string, signal?: AbortSignal): Promise<WeeklySlot[]> { | |
| 6 | + return client<WeeklySlot[]>(`/offerings/${id}/weekly-plan`, { signal }); | |
| 7 | +} |
src/api/offerings/getOfferings.tsadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; | |
| 3 | +import type { Offering } from "../client"; | |
| 4 | + | |
| 5 | +export type OfferingListParams = PageParams & { course?: string; grade_level?: number }; | |
| 6 | + | |
| 7 | +export async function getOfferings(params?: OfferingListParams, signal?: AbortSignal): Promise<Page<Offering>> { | |
| 8 | + const query = new URLSearchParams(); | |
| 9 | + appendPageParams(query, params); | |
| 10 | + if (params?.course) query.set("course", params.course); | |
| 11 | + if (params?.grade_level != null) query.set("grade_level", String(params.grade_level)); | |
| 12 | + const value = query.toString(); | |
| 13 | + const data = await client<unknown>(`/offerings${value ? `?${value}` : ""}`, { signal }); | |
| 14 | + return normalizePage<Offering>(data); | |
| 15 | +} |
src/api/offerings/index.tsadded+14 -0
| @@ -0,0 +1,14 @@ | ||
| 1 | +export * from "./getOfferings"; | |
| 2 | +export * from "./getOfferingById"; | |
| 3 | +export * from "./postOffering"; | |
| 4 | +export * from "./patchOfferingById"; | |
| 5 | +export * from "./deleteOfferingById"; | |
| 6 | +export * from "./getOfferingSubjects"; | |
| 7 | +export * from "./postOfferingSubject"; | |
| 8 | +export * from "./deleteOfferingSubjectById"; | |
| 9 | +export * from "./getOfferingWeeklyPlan"; | |
| 10 | +export * from "./postOfferingWeeklySlot"; | |
| 11 | +export * from "./deleteOfferingWeeklySlotById"; | |
| 12 | +export * from "./getOfferingExamWeights"; | |
| 13 | +export * from "./patchOfferingExamWeight"; | |
| 14 | +export * from "./deleteOfferingExamWeightByKind"; |
src/api/offerings/patchOfferingById.tsadded+15 -0
| @@ -0,0 +1,15 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Offering } from "../client"; | |
| 3 | + | |
| 4 | +/** Omit to keep; an explicit null clears the field back to inherit. */ | |
| 5 | +export type UpdateOfferingBody = Partial<{ | |
| 6 | + title: string | null; | |
| 7 | + description: string | null; | |
| 8 | + default_ders_saati: number | null; | |
| 9 | + default_counts_toward_karne: boolean | null; | |
| 10 | +}>; | |
| 11 | + | |
| 12 | +// Manager+. Sections without their own override follow the change at once. | |
| 13 | +export function patchOfferingById(id: string, body: UpdateOfferingBody): Promise<Offering> { | |
| 14 | + return client<Offering>(`/offerings/${id}`, { method: "PATCH", body }); | |
| 15 | +} |
src/api/offerings/patchOfferingExamWeight.tsadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { ExamWeightEntry } from "../client"; | |
| 3 | + | |
| 4 | +// Manager+. `kind` must be one the school runs (400 `unknown_exam_kind`); | |
| 5 | +// `weight` 1..100. Inheriting sections pick the change up at once. | |
| 6 | +export function patchOfferingExamWeight(id: string, body: ExamWeightEntry): Promise<{ weights: ExamWeightEntry[] }> { | |
| 7 | + return client<{ weights: ExamWeightEntry[] }>(`/offerings/${id}/exam-weights`, { method: "PATCH", body }); | |
| 8 | +} |
src/api/offerings/postOffering.tsadded+17 -0
| @@ -0,0 +1,17 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Offering } from "../client"; | |
| 3 | + | |
| 4 | +export type CreateOfferingBody = { | |
| 5 | + course: string; | |
| 6 | + grade_level: number; | |
| 7 | + title?: string | null; | |
| 8 | + description?: string | null; | |
| 9 | + default_ders_saati?: number | null; | |
| 10 | + default_counts_toward_karne?: boolean | null; | |
| 11 | +}; | |
| 12 | + | |
| 13 | +// Manager+. Only a `course`-kind ders has a grade axis; a second template for | |
| 14 | +// the same (course, grade) is a 409 `offering_exists`. | |
| 15 | +export function postOffering(body: CreateOfferingBody): Promise<Offering> { | |
| 16 | + return client<Offering>("/offerings", { method: "POST", body }); | |
| 17 | +} |
src/api/offerings/postOfferingSubject.tsadded+7 -0
| @@ -0,0 +1,7 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { Subject } from "../client"; | |
| 3 | + | |
| 4 | +// Manager+. Re-selecting an already selected topic is a no-op success. | |
| 5 | +export function postOfferingSubject(id: string, subjectId: string): Promise<Subject> { | |
| 6 | + return client<Subject>(`/offerings/${id}/subjects`, { method: "POST", body: { subject: subjectId } }); | |
| 7 | +} |
src/api/offerings/postOfferingWeeklySlot.tsadded+10 -0
| @@ -0,0 +1,10 @@ | ||
| 1 | +import { client } from "../client"; | |
| 2 | +import type { WeeklySlot } from "../client"; | |
| 3 | + | |
| 4 | +/** Minutes past midnight; `weekday` 1 (Monday) .. 7. A null topic uses the title. */ | |
| 5 | +export type CreateWeeklySlotBody = { weekday: number; starts_at: number; ends_at: number; topic?: string | null }; | |
| 6 | + | |
| 7 | +// Manager+. 409 `slot_overlap` for an intersecting window, `slot_cap` when full. | |
| 8 | +export function postOfferingWeeklySlot(id: string, body: CreateWeeklySlotBody): Promise<WeeklySlot> { | |
| 9 | + return client<WeeklySlot>(`/offerings/${id}/weekly-plan`, { method: "POST", body }); | |
| 10 | +} |
src/lib/student-directory.test.tsmodified+9 -9
| @@ -2,8 +2,8 @@ import { describe, expect, test } from "vitest"; | ||
| 2 | 2 | import type { ClassGroup, PersonRef } from "@/api/client"; |
| 3 | 3 | import { sortByClass } from "@/lib/student-directory"; |
| 4 | 4 | |
| 5 | -const cls = (name: string, grade: string | null): ClassGroup => ({ | |
| 6 | - id: name, creator: null, name, grade, year: null, teacher: null, | |
| 5 | +const cls = (name: string, gradeLevel: number): ClassGroup => ({ | |
| 6 | + id: name, creator: null, name, grade_level: gradeLevel, year: null, teacher: null, | |
| 7 | 7 | }); |
| 8 | 8 | const person = (name: string): PersonRef => ({ |
| 9 | 9 | id: name, username: name.toLowerCase(), display_name: name, student_number: null, |
| @@ -12,12 +12,12 @@ const person = (name: string): PersonRef => ({ | ||
| 12 | 12 | describe("sortByClass", () => { |
| 13 | 13 | test("orders by grade, then şube, then name; classless students last", () => { |
| 14 | 14 | const rows = [ |
| 15 | - { person: person("Zeynep"), classes: [cls("10-B", "10")] }, | |
| 15 | + { person: person("Zeynep"), classes: [cls("10-B", 10)] }, | |
| 16 | 16 | { person: person("Ali"), classes: [] }, |
| 17 | - { person: person("Can"), classes: [cls("9-A", "9")] }, | |
| 18 | - { person: person("Ayşe"), classes: [cls("10-A", "10")] }, | |
| 19 | - { person: person("Burak"), classes: [cls("10-B", "10")] }, | |
| 20 | - { person: person("Deniz"), classes: [cls("9-B", "9")] }, | |
| 17 | + { person: person("Can"), classes: [cls("9-A", 9)] }, | |
| 18 | + { person: person("Ayşe"), classes: [cls("10-A", 10)] }, | |
| 19 | + { person: person("Burak"), classes: [cls("10-B", 10)] }, | |
| 20 | + { person: person("Deniz"), classes: [cls("9-B", 9)] }, | |
| 21 | 21 | ]; |
| 22 | 22 | expect(sortByClass(rows).map((row) => row.person.display_name)) |
| 23 | 23 | .toEqual(["Can", "Deniz", "Ayşe", "Burak", "Zeynep", "Ali"]); |
| @@ -25,8 +25,8 @@ describe("sortByClass", () => { | ||
| 25 | 25 | |
| 26 | 26 | test("files a student in several classes under the earliest one", () => { |
| 27 | 27 | const rows = [ |
| 28 | - { person: person("Ece"), classes: [cls("10-B", "10"), cls("9-A", "9")] }, | |
| 29 | - { person: person("Mert"), classes: [cls("9-B", "9")] }, | |
| 28 | + { person: person("Ece"), classes: [cls("10-B", 10), cls("9-A", 9)] }, | |
| 29 | + { person: person("Mert"), classes: [cls("9-B", 9)] }, | |
| 30 | 30 | ]; |
| 31 | 31 | const sorted = sortByClass(rows); |
| 32 | 32 | expect(sorted.map((row) => row.person.display_name)).toEqual(["Ece", "Mert"]); |