From 96a262ec29edfda691c1b80d2d0f539d8d88787d Mon Sep 17 00:00:00 2001 From: Nathaniel Tampus Date: Sun, 19 Mar 2023 20:43:00 +0800 Subject: [PATCH] minor cleanup --- server/src/db/models/game.model.ts | 15 ++++----------- server/src/socket/index.ts | 2 +- types/index.d.ts | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/server/src/db/models/game.model.ts b/server/src/db/models/game.model.ts index 1aabe77..d31d90b 100644 --- a/server/src/db/models/game.model.ts +++ b/server/src/db/models/game.model.ts @@ -5,7 +5,7 @@ export const activeGames: Array = []; // todo: join user and game relationship -const create = async (game: Game) => { +export const create = async (game: Game) => { try { const res = await db.query( `INSERT INTO "game"(pgn, white_id, black_id, winner) VALUES($1, $2, $3, $4) RETURNING *`, @@ -24,7 +24,7 @@ const create = async (game: Game) => { } }; -const find = async (where?: string, limit = 1) => { +export const find = async (where?: string, limit = 1) => { const query = where ? `SELECT * FROM "game"` : { @@ -49,7 +49,7 @@ const find = async (where?: string, limit = 1) => { } }; -const update = async (id: number, data: string) => { +export const update = async (id: number, data: string) => { try { const res = await db.query(`UPDATE "game" SET $1 WHERE id = $2 RETURNING *`, [data, id]); return { @@ -65,7 +65,7 @@ const update = async (id: number, data: string) => { } }; -const remove = async (id: number) => { +export const remove = async (id: number) => { try { const res = await db.query(`DELETE FROM "game" WHERE id = $1 RETURNING *`, [id]); return { @@ -80,10 +80,3 @@ const remove = async (id: number) => { return null; } }; - -export const GameModel = { - create, - find, - update, - remove -}; diff --git a/server/src/socket/index.ts b/server/src/socket/index.ts index 81ef55e..7c0c7ca 100644 --- a/server/src/socket/index.ts +++ b/server/src/socket/index.ts @@ -12,7 +12,7 @@ import { const socketConnect = (socket: Socket) => { const req = socket.request; - // re-analyze if this is necessary, or if io.use will handle logout + // review if this is necessary, or if io.use will handle logout socket.use((__, next) => { req.session.reload((err) => { if (err) { diff --git a/types/index.d.ts b/types/index.d.ts index e2452ec..25dd30c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -13,7 +13,7 @@ export interface Game { export interface User { id?: number | string; // string for guest IDs - name?: string; + name?: string | null; email?: string; connected?: boolean; // mainly for players, not spectators }