From 69376e51f70b0b4729dbfeb9c6796679656c8fb6 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 27 Dec 2020 13:08:26 -0700 Subject: [PATCH] Implement the GetPastQuestions event. --- server/src/events/GetPastQuestions.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/server/src/events/GetPastQuestions.ts b/server/src/events/GetPastQuestions.ts index 5328d8a..6c4c850 100644 --- a/server/src/events/GetPastQuestions.ts +++ b/server/src/events/GetPastQuestions.ts @@ -1,13 +1,28 @@ +import { games, log } from '../main'; import { Server, Socket } from 'socket.io'; export default (io: Server, socket: Socket, data: GetPastQuestions) => { try { - socket.emit(`Error`, { - status: 501, - message: `GetPastQuestions: Not Implemented Yet`, - source: `GetPastQuestions`, + + // Assert game exists + if (!games[data.game_code]) { + log.debug(`Can't delete game that doesn't exist: ${data.game_code}`); + socket.emit(`Error`, { + status: 404, + message: `Game with code ${data.game_code} could not be found`, + source: `GetPastQuestions` + }); + return; + }; + let game = games[data.game_code]; + let team = game.teams[data.team - 1]; + + log.silly(`Past questions retrieved for team ${data.team} (gID=${game.id})`); + socket.emit(`PastQuestions`, { + questions: team.questions }); - } catch (err) { + } + catch (err) { socket.emit(`Error`, { status: 500, message: `${err.name}: ${err.message}`,