From 79219bdce7581bc2aa0fb6520cb3abcc18c05941 Mon Sep 17 00:00:00 2001 From: sgfost Date: Fri, 17 Nov 2023 13:07:58 -0700 Subject: [PATCH] fix: admin past games view fixes - don't display highscores and winners for defeated games - show contact info for players without a full name given - add types for the game data resolves virtualcommons/planning#54 --- client/src/views/admin/Games.vue | 74 +++++++++++++------------------- server/src/entity/Game.ts | 4 +- server/src/services/game.ts | 10 ++++- shared/src/types.ts | 29 +++++++++++-- 4 files changed, 66 insertions(+), 51 deletions(-) diff --git a/client/src/views/admin/Games.vue b/client/src/views/admin/Games.vue index 937a38e0f..3e287150c 100644 --- a/client/src/views/admin/Games.vue +++ b/client/src/views/admin/Games.vue @@ -14,7 +14,7 @@
- +

Games

@@ -105,11 +105,8 @@ variant="light" size="sm" class="float-right" - :disabled="isInspectedGame(data.item.id)" - @click=" - players = data.item.players; - inspectedHighScore = data.item.highScore; - " + :disabled="data.item.id === inspectedGame?.id" + @click="inspectedGame = data.item" >Scoreboard @@ -118,8 +115,8 @@
- -

Game #{{ players[0].gameId }} Scoreboard

+ +

Game #{{ inspectedGame.players[0].gameId }} Scoreboard

@@ -143,8 +140,8 @@ variant="success" v-if=" isEligibleForPrize(data.item.user) && - inspectedHighScore && - data.item.points === inspectedHighScore + inspectedGame.highScore && + data.item.points === inspectedGame.highScore " >winner @@ -177,12 +174,13 @@ diff --git a/server/src/entity/Game.ts b/server/src/entity/Game.ts index 3f42985c1..9857e7bf3 100644 --- a/server/src/entity/Game.ts +++ b/server/src/entity/Game.ts @@ -1,4 +1,4 @@ -import { GameType } from "@port-of-mars/shared/types"; +import { GameStatus, GameType } from "@port-of-mars/shared/types"; import { Column, CreateDateColumn, @@ -48,7 +48,7 @@ export class Game { players!: Array; @Column({ default: "incomplete" }) - status: "incomplete" | "defeat" | "victory" | "failure" = "incomplete"; + status: GameStatus = "incomplete"; @OneToOne(type => Player, { nullable: true }) @JoinColumn() diff --git a/server/src/services/game.ts b/server/src/services/game.ts index 56d562e33..cae9667b7 100644 --- a/server/src/services/game.ts +++ b/server/src/services/game.ts @@ -21,7 +21,10 @@ export class GameService extends BaseService { } async getTotalCompletedGames( - status: GameStatus | Array = [{ status: "victory" }, { status: "defeat" }] + status: { status: GameStatus } | Array<{ status: GameStatus }> = [ + { status: "victory" }, + { status: "defeat" }, + ] ): Promise { return await this.em.getRepository(Game).count({ where: status, @@ -56,7 +59,10 @@ export class GameService extends BaseService { } async getTotalGamesWithBots( - status: GameStatus | Array = [{ status: "victory" }, { status: "defeat" }] + status: { status: GameStatus } | Array<{ status: GameStatus }> = [ + { status: "victory" }, + { status: "defeat" }, + ] ): Promise { return this.em .getRepository(Game) diff --git a/shared/src/types.ts b/shared/src/types.ts index cf7d3a27a..e5907916d 100644 --- a/shared/src/types.ts +++ b/shared/src/types.ts @@ -20,12 +20,15 @@ export const MODERATION_ACTION_TYPES = [MUTE, BAN, NONE]; export interface ClientSafeUser { id: number; + email?: string; + name?: string; username: string; isAdmin: boolean; isMuted: boolean; isBanned: boolean; passedQuiz?: boolean; isVerified?: boolean; + isSystemBot?: boolean; dateConsented?: Date; participantId?: string; } @@ -120,6 +123,28 @@ export interface ModerationActionClientData { dateMuteExpires?: Date; } +export interface AdminGameData { + id: string; + status: GameStatus; + type: GameType; + roomId: string; + buildId: string; + dateCreated: string; + dateFinalized: string; + tournamentRoundId: number; + treatmentId?: number; + highScore?: number; + players: Array<{ + id: number; + role: Role; + userId: number; + playerIp: string; + gameId: number; + points: number; + user: ClientSafeUser; + }>; +} + export interface MarsLogData { category: string; message: string; @@ -417,9 +442,7 @@ export interface SoloPlayerStatItem { maxRound: number; } -export interface GameStatus { - status: "incomplete" | "defeat" | "victory" | "failure" | "incomplete"; -} +export type GameStatus = "incomplete" | "defeat" | "victory" | "failure" | "incomplete"; export interface InspectData { players: Array<{ username: string; role: string; isBot: boolean; points: number }>;