feat(tour): added tournament history page :D

This commit is contained in:
Maieul BOYER 2026-01-13 14:09:25 +01:00 committed by Maix0
parent 75f3c2a769
commit aca2dbd070
13 changed files with 245 additions and 4 deletions

View file

@ -66,6 +66,7 @@ CREATE TABLE IF NOT EXISTS tournament (
id TEXT PRIMARY KEY NOT NULL,
time TEXT NOT NULL default (datetime ('now')),
owner TEXT NOT NULL,
playerCount INTEGER NOT NULL,
FOREIGN KEY (owner) REFERENCES user (id)
);

View file

@ -36,7 +36,7 @@ export const TournamentImpl: Omit<ITournamentDb, keyof Database> = {
): TournamentData | null {
// Fetch tournament
const tournament = this
.prepare('SELECT id, time, owner FROM tournament WHERE id = @id')
.prepare('SELECT * FROM tournament WHERE id = @id')
.get({ id }) as TournamentTable;
if (!tournament) {
@ -90,7 +90,7 @@ export const TournamentImpl: Omit<ITournamentDb, keyof Database> = {
): void {
const tournamentId = newUUID() as TournamentId;
this.prepare('INSERT INTO tournament (id, owner) VALUES (@id, @owner)').run({ id: tournamentId, owner });
this.prepare('INSERT INTO tournament (id, owner, playerCount) VALUES (@id, @owner, @count)').run({ id: tournamentId, owner, count: users.length });
for (const u of users) {
this.prepare('INSERT INTO tour_user (user, nickname, score, tournament) VALUES (@id, @name, @score, @tournament)').run({ id: u.id, name: u.name, score: u.score, tournament: tournamentId });
}
@ -115,6 +115,7 @@ export interface TournamentTable {
id: TournamentId;
time: string;
owner: UserId;
playerCount: number;
}
export interface TournamentUser {

View file

@ -2497,12 +2497,16 @@
"data": {
"type": "object",
"required": [
"playerCount",
"owner",
"users",
"games",
"time"
],
"properties": {
"playerCount": {
"type": "number"
},
"owner": {
"type": "string",
"description": "ownerId"
@ -2736,11 +2740,15 @@
"items": {
"type": "object",
"required": [
"playerCount",
"id",
"owner",
"time"
],
"properties": {
"playerCount": {
"type": "number"
},
"id": {
"type": "string",
"description": "tournamentId"

View file

@ -355,12 +355,16 @@
"data": {
"type": "object",
"required": [
"playerCount",
"owner",
"users",
"games",
"time"
],
"properties": {
"playerCount": {
"type": "number"
},
"owner": {
"type": "string",
"description": "ownerId"
@ -591,11 +595,15 @@
"items": {
"type": "object",
"required": [
"playerCount",
"id",
"owner",
"time"
],
"properties": {
"playerCount": {
"type": "number"
},
"id": {
"type": "string",
"description": "tournamentId"

View file

@ -11,6 +11,7 @@ type TournamentDataParams = Static<typeof TournamentDataParams>;
const TournamentDataResponse = {
'200': typeResponse('success', 'tournamentData.success', {
data: Type.Object({
playerCount: Type.Number(),
owner: Type.String({ description: 'ownerId' }),
users: Type.Array(
Type.Object({
@ -65,8 +66,10 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
'tournamentData.failure.notFound',
);
}
console.log(data);
const typed_res: TournamentDataResponse['200']['payload']['data'] =
{
playerCount: data.playerCount,
owner: data.owner,
time: data.time,
users: data.users.map((v) => ({

View file

@ -6,6 +6,7 @@ const TournamentListResponse = {
'200': typeResponse('success', 'tournamentList.success', {
data: Type.Array(
Type.Object({
playerCount: Type.Number(),
id: Type.String({ description: 'tournamentId' }),
owner: Type.String({ description: 'ownerId' }),
time: Type.String(),