Fixes initializing the groups

parent 410b9c93
...@@ -97,16 +97,11 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> { ...@@ -97,16 +97,11 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
DbDAO.deleteMany(DbCollection.Members, { currentQuizName: removedQuiz.name }); DbDAO.deleteMany(DbCollection.Members, { currentQuizName: removedQuiz.name });
} }
public getMemberAmountPerQuizGroup(name: string): object { public getMemberAmountPerQuizGroup(name: string, groups: Array<string>): object {
const result = {}; const result = {};
groups.forEach(g => result[g] = 0);
this.getMembersOfQuiz(name).forEach(member => { this.getMembersOfQuiz(name).forEach(member => {
const targetResult = result[member.groupName];
if (!targetResult) {
result[member.groupName] = 1;
return;
}
result[member.groupName]++; result[member.groupName]++;
}); });
......
...@@ -699,8 +699,10 @@ export class QuizRouter extends AbstractRouter { ...@@ -699,8 +699,10 @@ export class QuizRouter extends AbstractRouter {
let groupName = 'Default'; let groupName = 'Default';
if (activeQuiz.sessionConfig.nicks.memberGroups.length > 1) { if (activeQuiz.sessionConfig.nicks.memberGroups.length > 1) {
const memberGroupLoad = MemberDAO.getMemberAmountPerQuizGroup(activeQuiz.name); const memberGroupLoad = MemberDAO.getMemberAmountPerQuizGroup(activeQuiz.name, activeQuiz.sessionConfig.nicks.memberGroups);
groupName = Object.entries(memberGroupLoad).sort((a, b) => a[1] - b[1])[0][0]; if (memberGroupLoad) {
groupName = Object.entries(memberGroupLoad).sort((a, b) => a[1] - b[1])[0][0];
}
} }
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment