diff options
Diffstat (limited to '')
-rw-r--r-- | controllers/games/gameId.js | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/controllers/games/gameId.js b/controllers/games/gameId.js index 9487743..2bc0a5e 100644 --- a/controllers/games/gameId.js +++ b/controllers/games/gameId.js @@ -9,16 +9,19 @@ function makePageData(user, game) { } export function gameId_get(req, res) { - const game = JSON.parse(getGame(req.params.gameId).data); - if (game) { - if (game.player1.id === req.session.user.id) { - game.letters = game.player1.letters; - delete game.player2.letters; - } else { - game.letters = game.player2.letters; - delete game.player1.letters; + const gameData = getGame(req.params.gameId); + if (gameData) { + const game = JSON.parse(gameData.data); + if (game) { + if (game.player1.id === req.session.user.id) { + game.letters = game.player1.letters; + delete game.player2.letters; + } else { + game.letters = game.player2.letters; + delete game.player1.letters; + } + return res.render('game', makePageData(req.session.user, game)); } - return res.render('game', makePageData(req.session.user, game)); - } + } // we got null or undefined from the getGame database request return res.redirect('/games'); } |