From 91e284d685dab7525c9526be1cb264a7a9c65c5c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 10 Mar 2021 16:03:54 +0100 Subject: recent games on user page working :tada: --- api/api.ts | 4 +++- api/user/games.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'api') diff --git a/api/api.ts b/api/api.ts index 2746238..0b37441 100644 --- a/api/api.ts +++ b/api/api.ts @@ -38,6 +38,8 @@ export interface userGameTotals { win: number; } +export type outcome = "w" | "l" | "d"; + export interface userGames { totals: userGameTotals; games: Array; @@ -49,7 +51,7 @@ export interface gameInfo { id: string; moves: Array; opponent: string; - outcome: "w"|"l"|"d"; + outcome: outcome; parent?: string; private: boolean; rating?: number; diff --git a/api/user/games.py b/api/user/games.py index 6073af2..95bd38a 100644 --- a/api/user/games.py +++ b/api/user/games.py @@ -25,7 +25,7 @@ def game_info(game_id, user_id = None): ]) + " from games where game_id = ?", [game_id]).fetchone() is_player_1 = game[4] != user_id outcome = "d" if game[5] == "d" else \ - "w" if game[5] == "w" and is_player_1 else "d" + "w" if game[5] == "w" and is_player_1 else "l" return { "id": game[0], "parent": game[1], @@ -70,7 +70,7 @@ def sum_games(user_id): #! SANITIZE USER_ID FIRST } def fetch_games(user_id, count): - game_ids = cursor.execute("select game_id from games where player_1_id = ? or player_2_id = ? order by created", [user_id, user_id]).fetchmany(count) + game_ids = cursor.execute("select game_id from games where player_1_id = ? or player_2_id = ? order by created desc", [user_id, user_id]).fetchmany(count) export = [] for game_id in game_ids: -- cgit v1.2.3