0
0
Fork 0

Implement the GetPastQuestions event.

This commit is contained in:
Oliver-Akins 2020-12-27 13:08:26 -07:00
parent 727e41f2b0
commit 69376e51f7

View file

@ -1,13 +1,28 @@
import { games, log } from '../main';
import { Server, Socket } from 'socket.io'; import { Server, Socket } from 'socket.io';
export default (io: Server, socket: Socket, data: GetPastQuestions) => { export default (io: Server, socket: Socket, data: GetPastQuestions) => {
try { try {
// Assert game exists
if (!games[data.game_code]) {
log.debug(`Can't delete game that doesn't exist: ${data.game_code}`);
socket.emit(`Error`, { socket.emit(`Error`, {
status: 501, status: 404,
message: `GetPastQuestions: Not Implemented Yet`, message: `Game with code ${data.game_code} could not be found`,
source: `GetPastQuestions`, source: `GetPastQuestions`
}); });
} catch (err) { 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) {
socket.emit(`Error`, { socket.emit(`Error`, {
status: 500, status: 500,
message: `${err.name}: ${err.message}`, message: `${err.name}: ${err.message}`,