feat(ttt/database): prefixed TTT database thingy to avoid pong conflicts

This commit is contained in:
Maieul BOYER 2026-01-05 15:43:32 +01:00 committed by Maix0
parent d222dfd332
commit d59e8f93c8
3 changed files with 12 additions and 25 deletions

View file

@ -27,8 +27,7 @@ CREATE TABLE IF NOT EXISTS tictactoe (
id TEXT PRIMARY KEY NOT NULL,
player1 TEXT NOT NULL,
player2 TEXT NOT NULL,
outcome TEXT NOT NULL
-- FOREIGN KEY(player1) REFERENCES user(id)
-- FOREIGN KEY(player2) REFERENCES user(id)
outcome TEXT NOT NULL,
FOREIGN KEY(player1) REFERENCES user(id),
FOREIGN KEY(player2) REFERENCES user(id)
);

View file

@ -1,11 +1,10 @@
import UUID from '@shared/utils/uuid';
import type { Database } from './_base';
import { UserId } from './user';
// import { UserId } from './user';
// describe every function in the object
export interface ITicTacToeDb extends Database {
setGameOutcome(this: ITicTacToeDb, id: GameId, player1: UserId, player2: UserId, outcome: string): void,
// asyncFunction(id: TemplateId): Promise<TemplateData | undefined>,
setTTTGameOutcome(this: ITicTacToeDb, id: TTTGameId, player1: UserId, player2: UserId, outcome: string): void,
};
export const TicTacToeImpl: Omit<ITicTacToeDb, keyof Database> = {
@ -15,29 +14,18 @@ export const TicTacToeImpl: Omit<ITicTacToeDb, keyof Database> = {
* @param gameId The game we want to write the outcome of.
*
*/
setGameOutcome(this: ITicTacToeDb, id: GameId, player1: string, player2: string, outcome: string): void {
setTTTGameOutcome(this: ITicTacToeDb, id: TTTGameId, player1: UserId, player2: UserId, outcome: string): void {
// Find a way to retrieve the outcome of the game.
this.prepare('INSERT INTO tictactoe (id, player1, player2, outcome) VALUES (@id, @player1, @player2, @outcome)').run({ id, player1, player2, outcome });
},
/**
* whole function description
*
* @param id the argument description
*
* @returns what does the function return ?
*/
// async asyncFunction(this: ITemplateDb, id: TemplateId): Promise<TemplateData | undefined> {
// void id;
// return undefined;
// },
};
export type GameId = string & { readonly __brand: unique symbol };
export type TTTGameId = UUID & { readonly __brand: unique symbol };
export type TicTacToeData = {
readonly id: GameId;
readonly player1: string;
readonly player2: string;
export type TicTacToeGame = {
readonly id: TTTGameId;
readonly player1: UserId;
readonly player2: UserId;
readonly outcome: string;
};

View file

@ -98,7 +98,7 @@ export class StateI {
this.gameUpdate(gameId, u2.socket);
if (g.checkState() !== 'ongoing') {
this.cleanupGame(gameId, g);
this.fastify.db.setGameOutcome(gameId, u1.userId, u2.userId, g.checkState());
this.fastify.db.setTTTGameOutcome(gameId, u1.userId, u2.userId, g.checkState());
}
}, 100);
}