aboutsummaryrefslogtreecommitdiff
path: root/src/mock.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/mock.ts')
-rw-r--r--src/mock.ts26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/mock.ts b/src/mock.ts
index 14d408d..bbbc771 100644
--- a/src/mock.ts
+++ b/src/mock.ts
@@ -1,6 +1,26 @@
import { Graduation, GraduationChange } from "./graduation-common.ts";
import { Student } from "./student-common.ts";
+export function getName() {
+ let name = "";
+
+ const params = new URLSearchParams(document.location.search);
+ if (params.has("firstname")) name = params.get("firstname")!;
+ if (params.has("lastname")) name += " " + params.get("lastname")!;
+
+ return name.trim();
+}
+
+globalThis.M = {
+ cfg: {
+ userId: (function () {
+ const name = getName();
+ return _fetchStudentsMock().filter((s) => s.name === name)[0].id;
+ })(),
+ courseId: 1337,
+ },
+};
+
const students = [
new Student(1, "foo bar"),
new Student(2, "maxi mustermensch"),
@@ -12,7 +32,7 @@ const students = [
new Student(8, "6"),
];
-async function fetchStudentsMock(id?: number, name?: string) {
+function _fetchStudentsMock(id?: number, name?: string) {
return students.filter((s) => {
return (
(typeof id === "undefined" || s.id === id) &&
@@ -21,6 +41,10 @@ async function fetchStudentsMock(id?: number, name?: string) {
});
}
+async function fetchStudentsMock(id?: number, name?: string) {
+ return _fetchStudentsMock(id, name);
+}
+
async function fetchSubjectsMock() {
return ["Mathe", "Deutsch", "Englisch"];
}