aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-10 16:03:54 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-10 16:03:54 +0100
commit91e284d685dab7525c9526be1cb264a7a9c65c5c (patch)
tree85eed8b5e6e35bf17668ea8a75f9108d1ae41474 /api
parentf5b8dd384afb059aabc24af3539f30928c7f7da9 (diff)
recent games on user page working :tada:
Diffstat (limited to 'api')
-rw-r--r--api/api.ts4
-rw-r--r--api/user/games.py4
2 files changed, 5 insertions, 3 deletions
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<gameInfo>;
@@ -49,7 +51,7 @@ export interface gameInfo {
id: string;
moves: Array<number>;
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: