diff options
Diffstat (limited to 'js/group.js')
| -rw-r--r-- | js/group.js | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/js/group.js b/js/group.js index 103f368..7b3dfd1 100644 --- a/js/group.js +++ b/js/group.js @@ -21,19 +21,27 @@ class Group { } async getStudents() { - return students; + return this.students; } } let groups = new Map(); +let bycsGroups = 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)); + let group = groups.get(groupName); + + if (!group) { + group = new Group(groupName); + groups.set(groupName, group); + if (groupName != student.getGroupName()) { + bycsGroups.set(groupName, group); + } } - groups.get(groupName).addStudent(student); + + group.addStudent(student); // Create the individual student group const sGroupName = student.getGroupName(); @@ -51,9 +59,20 @@ async function fetchGroups() { } // Fetch all students and build the groups from them - const students = fetchStudents(); + const students = await fetchStudents(); buildGroups(students); return groups; } -export { Group, buildGroups, fetchGroups }; +async function fetchBycsGroups() { + if (bycsGroups.size) { + return bycsGroups; + } + + // Fetch all students and build the groups from them + const students = await fetchStudents(); + buildGroups(students); + return bycsGroups; +} + +export { Group, buildGroups, fetchGroups, fetchBycsGroups }; |
