summaryrefslogtreecommitdiff
path: root/controllers/games/gameId.js
diff options
context:
space:
mode:
authorJulien Dessaux2022-11-22 22:55:36 +0100
committerJulien Dessaux2022-11-22 22:55:36 +0100
commit038c877aed55cffdb4401a4c7e7b15b113798145 (patch)
treee2902779e76ba8bd60b63be0e512a3c112530d68 /controllers/games/gameId.js
parentAdded basic games handling (diff)
downloadjeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.gz
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.tar.bz2
jeux-de-mots-038c877aed55cffdb4401a4c7e7b15b113798145.zip
Implemented game creation
Diffstat (limited to '')
-rw-r--r--controllers/games/gameId.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/controllers/games/gameId.js b/controllers/games/gameId.js
index c87a857..d3363fd 100644
--- a/controllers/games/gameId.js
+++ b/controllers/games/gameId.js
@@ -1,17 +1,24 @@
import { getGame } from "../../database/games.js";
-function makePageData(user, cwdata) {
+function makePageData(user, game) {
return {
title: "Jouer",
user: user,
- CWDATA: cwdata,
+ data: game,
};
}
export function gameId_get(req, res) {
- const game = getGame(req.params.gameId);
- // TODO redirect if null
- let cwdata = game; // TODO reformat this object
- console.log(cwdata);
- return res.render("game", makePageData(req.session.user, cwdata));
+ 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;
+ }
+ return res.render("game", makePageData(req.session.user, game));
+ }
+ return res.redirect("/games");
}