diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:51:51 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:51:51 +0200 |
| commit | 582df8885a3573a728394b473b826616f8969316 (patch) | |
| tree | 9c21db03f4fbfd9956ee398e0d9194ebfa5b3234 /src/mock.ts | |
| parent | 46ac53e11b49a7f9cdb92c3559b05f41ce90122f (diff) | |
| download | bycs-sol-582df8885a3573a728394b473b826616f8969316.tar.gz bycs-sol-582df8885a3573a728394b473b826616f8969316.zip | |
convert a lot of js to typescript and use a single graduation DB
Diffstat (limited to 'src/mock.ts')
| -rw-r--r-- | src/mock.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mock.ts b/src/mock.ts new file mode 100644 index 0000000..220b1e3 --- /dev/null +++ b/src/mock.ts @@ -0,0 +1,81 @@ +import { Graduation, GraduationChange, Observation } from "./graduation-common.ts"; +import { Student } from "./student-common.ts"; +import { buildGroups } from "./group.ts"; + +const students = [ + new Student(1, 'foo bar', 'test'), + new Student(2, 'maxi mustermensch', 'test'), + new Student(3, 'b b b', '5a') +]; + +// Build the groups from our mock students +buildGroups(students); + +async function fetchStudentsMock(_id?: number, _name?: string, _group?: string) { + return students; +} + +async function fetchSubjectsMock() { + return ['Mathe', 'Deutsch', 'Englisch']; +} + +function fetchProgressMock(subject: string) { + return new Promise((resolve) => { + if (subject === "Mathe") { + resolve([40, 10, 3]); + } else if (subject === "Deutsch") { + resolve([10, 2, 0]); + } else if (subject === "Englisch") { + resolve([50, 25, 10]); + } else { + resolve([0, 0, 0]); + } + }); +} + +const graduations = new Map(); +for (const s of students) { + switch (s.name) { + case "foo bar": + graduations.set(s, Graduation.from(s, [ + GraduationChange.newGreenPointChange("Gute Arbeit", "Florian Fischer"), + GraduationChange.newOrangePointChange("", "Florian Fischer"), + ])); + break; + case "maxi mustermensch": + graduations.set(s, Graduation.from(s, [ + GraduationChange.newGreenPointChange("", "Florian Fischer"), + GraduationChange.newGreenPointChange("", "Florian Fischer"), + new GraduationChange(new Date(), s.id, "ObservationStart", "", "Florian Fischer", ""), + ])); + break; + case "b b b": + graduations.set(s, Graduation.from(s, [ + GraduationChange.newRedPointChange("", "Florian Fischer"), + ])); + } +} + +async function fetchGraduationMock(s: Student) { + return graduations.get(s); +} + +function submitGraduationChangeMock(s: Student, c: GraduationChange) { + if (s.graduation === null) throw new Error("no graduation"); + s.graduation.addChange(c); +} + +function submitObservationMock(s: Student, o: Observation) { + if (s.graduation === null) throw new Error("no graduation"); + if (s.graduation.observation === null) throw new Error("no observation period"); + s.graduation.observation.addObservation(o); +} + +export { + fetchStudentsMock, + fetchSubjectsMock, + fetchProgressMock, + fetchGraduationMock, + submitGraduationChangeMock, + submitObservationMock, +}; |
