diff --git a/src/@shared/src/database/init.sql b/src/@shared/src/database/init.sql index 71074e4..02c20f3 100644 --- a/src/@shared/src/database/init.sql +++ b/src/@shared/src/database/init.sql @@ -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) ); diff --git a/src/@shared/src/database/mixin/tictactoe.ts b/src/@shared/src/database/mixin/tictactoe.ts index 0f0950c..85a5494 100644 --- a/src/@shared/src/database/mixin/tictactoe.ts +++ b/src/@shared/src/database/mixin/tictactoe.ts @@ -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, + setTTTGameOutcome(this: ITicTacToeDb, id: TTTGameId, player1: UserId, player2: UserId, outcome: string): void, }; export const TicTacToeImpl: Omit = { @@ -15,29 +14,18 @@ export const TicTacToeImpl: Omit = { * @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 { - // 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; }; diff --git a/src/tic-tac-toe/src/state.ts b/src/tic-tac-toe/src/state.ts index bb2eeab..f35769d 100644 --- a/src/tic-tac-toe/src/state.ts +++ b/src/tic-tac-toe/src/state.ts @@ -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); }