diff options
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/games/gameId.js | 17 | ||||
-rw-r--r-- | controllers/games/root.js | 13 | ||||
-rw-r--r-- | controllers/play.js | 9 |
3 files changed, 30 insertions, 9 deletions
diff --git a/controllers/games/gameId.js b/controllers/games/gameId.js new file mode 100644 index 0000000..c87a857 --- /dev/null +++ b/controllers/games/gameId.js @@ -0,0 +1,17 @@ +import { getGame } from "../../database/games.js"; + +function makePageData(user, cwdata) { + return { + title: "Jouer", + user: user, + CWDATA: cwdata, + }; +} + +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)); +} diff --git a/controllers/games/root.js b/controllers/games/root.js new file mode 100644 index 0000000..ece7b74 --- /dev/null +++ b/controllers/games/root.js @@ -0,0 +1,13 @@ +import { listGames } from "../../database/games.js"; + +export function root_get(req, res) { + const data = { + title: "Liste des parties", + user: req.session.user, + games: listGames(req.session.user.id), + }; + for (let i=0; i<data.games.length; i++) { + data.games[i].data = JSON.parse(data.games[i].data); + } + return res.render("games", data); +} diff --git a/controllers/play.js b/controllers/play.js deleted file mode 100644 index c00d15d..0000000 --- a/controllers/play.js +++ /dev/null @@ -1,9 +0,0 @@ -function makeController(req, cwdata) { - return { - title: "Jouer", - user: req.session.user, - CWDATA: cwdata, - }; -} - -export default makeController; |