diff options
author | Julien Dessaux | 2023-02-11 21:46:06 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-02-11 21:46:06 +0100 |
commit | cffa0474dd892c13c3b0deee6d2e14e4637874b7 (patch) | |
tree | 1af375dc3dfc14355ffbbe47b30ddae0e680faa7 /controllers | |
parent | Improved makefile (diff) | |
download | jeux-de-mots-cffa0474dd892c13c3b0deee6d2e14e4637874b7.tar.gz jeux-de-mots-cffa0474dd892c13c3b0deee6d2e14e4637874b7.tar.bz2 jeux-de-mots-cffa0474dd892c13c3b0deee6d2e14e4637874b7.zip |
Improved games controller tests
Diffstat (limited to 'controllers')
-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'); } |