diff --git a/src/domain/party/party.controller.ts b/src/domain/party/party.controller.ts index edf44f9f6a335a00b61f02344292339e58d18ad9..f747bb0f9f632e9c3af0063663f9dc7a3071b862 100644 --- a/src/domain/party/party.controller.ts +++ b/src/domain/party/party.controller.ts @@ -158,14 +158,24 @@ export class PartyController { const run = await this.runService.getRunByPartyAndHost(userId); - const question = await this.partyService.getQuestion({ - id: run.id, - }); + try { + const question = await this.partyService.getQuestion({ + id: run.id, + }); + + this.sseService.sendEvent(user.partyId, { + type: 'nextQuestion', + data: question, + }); + } catch { + // if there are no question, send the end of the game + const scores = await this.partyService.getScoreboard(user.partyId); - this.sseService.sendEvent(user.partyId, { - type: 'nextQuestion', - data: question, - }); + this.sseService.sendEvent(user.partyId, { + type: 'gameEnded', + data: scores, + }); + } } @Get('leave/:party_id') diff --git a/src/domain/party/store/party-repository-on-db.ts b/src/domain/party/store/party-repository-on-db.ts index b54f99b0f353f4b41313c74c7a85350f6b2abc41..1f6c78b7d6e3e8894e9251b17d4f8a993b39afa2 100644 --- a/src/domain/party/store/party-repository-on-db.ts +++ b/src/domain/party/store/party-repository-on-db.ts @@ -181,10 +181,8 @@ export class PartyRepositoryOnDb implements PartyRepository { }); return runs.map((r) => ({ - user: { - id: r.QuizUser.id, - username: r.QuizUser.username, - }, + id: r.QuizUser.id, + username: r.QuizUser.username, score: r.score, })); } diff --git a/src/domain/party/store/party-repository.ts b/src/domain/party/store/party-repository.ts index 97d33b12f4821255aa6dfd02a443eb246ed23516..3426727d5bbb955c564ef747c27dab8c446765d2 100644 --- a/src/domain/party/store/party-repository.ts +++ b/src/domain/party/store/party-repository.ts @@ -28,5 +28,5 @@ export abstract class PartyRepository { }); abstract getScores( partyId: string, - ): Promise<{ user: { id: number; username: string }; score: number }[]>; + ): Promise<{ id: number; username: string; score: number }[]>; }