aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-10 17:50:22 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-10 17:50:22 +0100
commit1bfee312bf6a176f50bc6751ad6d3cb8a80be5d8 (patch)
tree4d80428c036ea6c63fd3ff30803252a87269a5f5 /api
parente7358f0d8a4ce56f7eed5927cfadf0ee29f4508f (diff)
game status in recent games thingy works better now
Diffstat (limited to 'api')
-rw-r--r--api/api.ts2
-rw-r--r--api/user/games.py7
2 files changed, 5 insertions, 4 deletions
diff --git a/api/api.ts b/api/api.ts
index 1db6e0e..1cf50ef 100644
--- a/api/api.ts
+++ b/api/api.ts
@@ -50,7 +50,7 @@ export interface gameInfo {
duration: number;
id: string;
moves: Array<number>;
- opponent: userInfo;
+ opponent?: userInfo;
outcome: outcome;
parent?: string;
private: boolean;
diff --git a/api/user/games.py b/api/user/games.py
index 009e5ee..1cd19f2 100644
--- a/api/user/games.py
+++ b/api/user/games.py
@@ -30,12 +30,13 @@ def game_info(game_id, user_id = None):
"private", # 13
]) + " from games where game_id = ?", [game_id]).fetchone()
is_player_1 = game[4] != user_id
+ opponent = game[4] if is_player_1 else game[3]
return {
"id": game[0],
"parent": game[1],
- "moves": [int(move) for move in str(game[2]).split(",")],
- "opponent": format_user(game[4] if is_player_1 else game[3]),
- "outcome": outcome(game[5], is_player_1),
+ "moves": [] if len(game[2]) == 0 else [int(move) for move in str(game[2] + "0").split(",")],
+ "opponent": None if not opponent else format_user(opponent),
+ "outcome": None if not game[5] else outcome(game[5], is_player_1),
"created": game[6],
"started": game[7],
"duration": game[8],