Implement the GetPastQuestions event.
This commit is contained in:
parent
727e41f2b0
commit
69376e51f7
1 changed files with 20 additions and 5 deletions
|
|
@ -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}`,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue