summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-06-12 16:42:33 +0200
committerTor Andersson <tor@ccxvii.net>2022-06-13 20:20:01 +0200
commit072766b71f9441fdd2796b8dd1137b90acd5a561 (patch)
tree27dce1ed3f835a964b8dcf1d5f976d2ac1b507e2 /server.js
parent8175df9f9af2393964f053af5a98851c376e1675 (diff)
downloadserver-072766b71f9441fdd2796b8dd1137b90acd5a561.tar.gz
List playing and recently finished games on user pages.
Diffstat (limited to 'server.js')
-rw-r--r--server.js27
1 files changed, 25 insertions, 2 deletions
diff --git a/server.js b/server.js
index e8d9c14..52c9bcf 100644
--- a/server.js
+++ b/server.js
@@ -567,7 +567,14 @@ app.get('/user/:who_name', function (req, res) {
who.avatar = get_avatar(who.mail)
who.ctime = human_date(who.ctime)
who.atime = human_date(who.atime)
- res.render('user.pug', { user: req.user, who: who })
+ let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id: who.user_id })
+ annotate_games(games, 0)
+ res.render('user.pug', {
+ user: req.user,
+ who: who,
+ active_games: games.filter(game => !is_finished_game(game)),
+ finished_games: games.filter(is_finished_game),
+ })
} else {
return res.status(404).send("Invalid user name.")
}
@@ -1098,7 +1105,7 @@ app.get('/games', function (req, res) {
})
app.get('/games/active', must_be_logged_in, function (req, res) {
- let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({user_id: req.user.user_id})
+ let games = QUERY_LIST_ACTIVE_GAMES_OF_USER.all({ user_id: req.user.user_id })
annotate_games(games, req.user.user_id)
res.render('games_active.pug', {
user: req.user,
@@ -1115,10 +1122,26 @@ app.get('/games/finished', must_be_logged_in, function (req, res) {
annotate_games(games, req.user.user_id)
res.render('games_finished.pug', {
user: req.user,
+ who: req.user,
finished_games: games,
})
})
+app.get('/games/finished/:who_name', function (req, res) {
+ let who = SQL_SELECT_USER_BY_NAME.get(req.params.who_name)
+ if (who) {
+ let games = QUERY_LIST_FINISHED_GAMES_OF_USER.all({ user_id: who.user_id })
+ annotate_games(games, 0)
+ res.render('games_finished.pug', {
+ user: req.user,
+ who: who,
+ finished_games: games,
+ })
+ } else {
+ return res.status(404).send("Invalid user name.")
+ }
+})
+
app.get('/games/public', function (req, res) {
let games = QUERY_LIST_PUBLIC_GAMES.all()
if (req.user)