import { getCourseParticipantsUrl } from "./config.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 students; } } let groups = new Map(); function buildGroups(students) { for (const student of students) { for (const groupName of student.groups) { if (!groups.has(groupName)) { groups.set(groupName, new Group(groupName)); } groups.get(groupName).addStudent(student); // Create the individual student group const sGroupName = student.getGroupName(); groups.set(sGroupName, new Group(sGroupName, [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 = fetchStudents(); buildGroups(students); return groups; } export { Group, buildGroups, fetchGroups };