summaryrefslogtreecommitdiff
path: root/controllers/games/gameId.js
blob: 9487743a1de2ad651f0a7411b9b7b10cf6983047 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { getGame } from '../../database/games.js';

function makePageData(user, game) {
	return {
		title: 'Jouer',
		user: user,
		data: 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;
		}
		return res.render('game', makePageData(req.session.user, game));
	}
	return res.redirect('/games');
}