Fixes error when having multiple teams in the quiz and setting autoJoinToGroup to true

parent db4aa45b
......@@ -13,6 +13,14 @@ import QuizDAO from './quiz/QuizDAO';
class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
public static getInstance(): MemberDAO {
if (!this.instance) {
this.instance = new MemberDAO();
}
return this.instance;
}
constructor() {
super([]);
......@@ -26,14 +34,6 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
});
}
public static getInstance(): MemberDAO {
if (!this.instance) {
this.instance = new MemberDAO();
}
return this.instance;
}
public getMemberByName(name: string): MemberEntity {
return this.storage.find(val => val.name === name);
}
......@@ -97,6 +97,22 @@ class MemberDAO extends AbstractDAO<Array<MemberEntity>> {
DbDAO.deleteMany(DbCollection.Members, { currentQuizName: removedQuiz.name });
}
public getMembersByQuizGroup(name: string): object {
const result = {};
this.getMembersOfQuiz(name).forEach(member => {
const targetResult = result[member.groupName];
if (!targetResult) {
result[member.groupName] = 1;
return;
}
result[member.groupName]++;
});
return result;
}
private notifyQuizDAO(member: MemberEntity): void {
const quiz = QuizDAO.getQuizByName(member.currentQuizName);
if (!quiz) {
......
......@@ -55,17 +55,18 @@ export enum MessageProtocol {
EndOfQuestions = 'EndOfQuestions', //
CurrentState = 'CurrentState', //
GetStartTime = 'GetStartTime', //
GetLeaderboardData = 'GetLeaderboardData', //
Reserved = 'Reserved', //
Removed = 'Removed', //
GetThemes = 'GetThemes', //
QuizAssets = 'QuizAssets', //
Render = 'Render', //
Connected = 'Connected', //
QuizNotFound = 'QuizNotFound', //
Connect = 'Connect', //
Disconnect = 'Disconnect', //
Editable = 'Editable', //
GetLeaderboardData = 'GetLeaderboardData', //
Reserved = 'Reserved', //
Removed = 'Removed', //
GetThemes = 'GetThemes', //
QuizAssets = 'QuizAssets', //
Render = 'Render', //
Connected = 'Connected', //
QuizNotFound = 'QuizNotFound', //
Connect = 'Connect', //
Disconnect = 'Disconnect', //
Editable = 'Editable', //
GetFreeMemberGroup = 'GetFreeMemberGroup', //
}
export const Message = {
......
export function sortDescending(a, b): number {
return a === b ? 0 : b - a;
}
......@@ -686,6 +686,31 @@ export class QuizRouter extends AbstractRouter {
return buffer;
}
@Get('/member-group')
public getFreeMemberGroup(@HeaderParam('authorization') authorization: string): object {
const activeQuiz: IQuizEntity = QuizDAO.getQuizByToken(authorization);
if (!activeQuiz) {
return {
status: StatusProtocol.Failed,
step: MessageProtocol.GetFreeMemberGroup,
payload: {},
};
}
let groupName = 'Default';
if (activeQuiz.sessionConfig.nicks.memberGroups.length > 1) {
groupName = Object.values(MemberDAO.getMembersByQuizGroup(activeQuiz.name)).sort()[0];
}
return {
status: StatusProtocol.Success,
step: MessageProtocol.GetFreeMemberGroup,
payload: {
groupName,
},
};
}
@Get('/leaderboard/:quizName/:amount/:questionIndex?')
public getLeaderBoardData(
@Param('quizName') quizName: string, //
......
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