diff options
Diffstat (limited to 'src/student-common.ts')
| -rw-r--r-- | src/student-common.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/student-common.ts b/src/student-common.ts new file mode 100644 index 0000000..a76a816 --- /dev/null +++ b/src/student-common.ts @@ -0,0 +1,42 @@ +import type { Graduation } from "./graduation-common.ts"; +/** + * Class to represent Students. + */ +export class Student { + id: number; + name: string; + group: string; + graduation: Graduation | null = null; + + constructor(id: number, name: string, group: string) { + this.id = id; + this.name = name; + this.group = group; + } + + getGroup() { + return this.group; + } + + /** + static async fetchById(id: number) { + let name = ""; + let group = ""; + + const res = await fetch(`/user/view.php?id=${id}&course=${getCourseId()}`); + const doc = new DOMParser().parseFromString(await res.text(), "text/html"); + + name = doc.querySelector("div.page-header-headings > h2")!.textContent; + + const cards = doc.querySelectorAll("div.card-body dl"); + for (const card of cards) { + if (card.querySelector("dt")!.textContent !== "Gruppe") + continue; + group = card.querySelector("dd > a")!.textContent; + break; + } + + return new Student(id, name, group); + } + */ +} |
