aboutsummaryrefslogtreecommitdiff
path: root/src/group.js
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-08-03 14:31:25 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-08-03 14:31:25 +0200
commit6839831af54cd9302119bcc3bffafe10475958d4 (patch)
tree12a1c1fbd864e9579cb9c3a09d4bf4686a280b73 /src/group.js
parentfccb70cbd876785f6833dfe6efc10ec9e445556d (diff)
downloadbycs-sol-6839831af54cd9302119bcc3bffafe10475958d4.tar.gz
bycs-sol-6839831af54cd9302119bcc3bffafe10475958d4.zip
refactor project structure
* merge sites into single project root * fix name of mass-graduation site * enable typescript support
Diffstat (limited to 'src/group.js')
-rw-r--r--src/group.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/group.js b/src/group.js
new file mode 100644
index 0000000..ba5e1a0
--- /dev/null
+++ b/src/group.js
@@ -0,0 +1,57 @@
+import { getCourseParticipantsUrl } from "./utils-ENV.js";
+import { fetchStudents } from "./student-ENV.js";
+
+/**
+ * Class to represent a Group of Students.
+ */
+class Group {
+ constructor(name, students) {
+ this.name = name;
+ if (!students) {
+ this.students = [];
+ }
+ }
+
+ setStudents(students) {
+ this.students = students;
+ }
+
+ addStudent(student) {
+ this.students.push(student);
+ }
+
+ async getStudents() {
+ return this.students;
+ }
+}
+
+let groups = new Map();
+
+function buildGroups(students) {
+ 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);
+ }
+}
+
+/**
+ * Fetch all Groups and return them as a map.
+ */
+async function fetchGroups() {
+ if (groups.size) {
+ return groups;
+ }
+
+ // Fetch all students and build the groups from them
+ const students = await fetchStudents();
+ buildGroups(students);
+ return groups;
+}
+
+export { Group, buildGroups, fetchGroups };