aboutsummaryrefslogtreecommitdiff
path: root/src/group.ts
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-08-05 11:51:51 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-08-05 11:51:51 +0200
commit582df8885a3573a728394b473b826616f8969316 (patch)
tree9c21db03f4fbfd9956ee398e0d9194ebfa5b3234 /src/group.ts
parent46ac53e11b49a7f9cdb92c3559b05f41ce90122f (diff)
downloadbycs-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/group.ts')
-rw-r--r--src/group.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/group.ts b/src/group.ts
new file mode 100644
index 0000000..e840ffd
--- /dev/null
+++ b/src/group.ts
@@ -0,0 +1,45 @@
+import type { Student } from "./student-common.ts";
+
+/**
+ * Class to represent a Group of Students.
+ */
+class Group {
+ name: string;
+ students: Array<Student> = [];
+
+ constructor(name: string, students?: Array<Student>) {
+ this.name = name;
+ if (typeof students !== "undefined") {
+ this.students = students;
+ }
+ }
+
+ setStudents(students: Array<Student>) {
+ this.students = students;
+ }
+
+ addStudent(student: Student) {
+ this.students.push(student);
+ }
+
+ async getStudents() {
+ return this.students;
+ }
+}
+
+const groups = new Map();
+
+function buildGroups(students: Array<Student>) {
+ for (const student of students) {
+ let group = groups.get(student.group);
+
+ if (!group) {
+ group = new Group(student.group);
+ groups.set(student.group, group);
+ }
+
+ group.addStudent(student);
+ }
+}
+
+export { Group, buildGroups, groups as _groups };