From 3c95af8ede67353db7275244f908a69384d0c47c Mon Sep 17 00:00:00 2001 From: bgoulard Date: Sat, 10 Jan 2026 17:13:42 +0100 Subject: [PATCH] eslint on api for paused games --- src/pong/src/game.ts | 2 +- src/pong/src/routes/createPausedGame.ts | 30 ++++++++++--------------- src/pong/src/routes/startPausedGame.ts | 24 ++++++++++---------- src/pong/src/state.ts | 13 +++++------ 4 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/pong/src/game.ts b/src/pong/src/game.ts index 5dad0df..934e081 100644 --- a/src/pong/src/game.ts +++ b/src/pong/src/game.ts @@ -132,7 +132,7 @@ export class Pong { public sendSig : boolean = false; public ready_checks: [boolean, boolean] = [false, false]; - public rdy_timer : number = Date.now(); // init rdy timer from class creation start + public rdy_timer : number = Date.now(); public score: [number, number] = [0, 0]; public local: boolean = false; diff --git a/src/pong/src/routes/createPausedGame.ts b/src/pong/src/routes/createPausedGame.ts index 793b8d7..9b89258 100644 --- a/src/pong/src/routes/createPausedGame.ts +++ b/src/pong/src/routes/createPausedGame.ts @@ -1,15 +1,9 @@ -import { isNullish, MakeStaticResponse, typeResponse } from "@shared/utils"; -import { FastifyPluginAsync } from "fastify"; -import { Static, Type } from "typebox"; -import { State } from "../state"; -import { UserId } from "@shared/database/mixin/user"; +import { isNullish, MakeStaticResponse, typeResponse } from '@shared/utils'; +import { FastifyPluginAsync } from 'fastify'; +import { Static, Type } from 'typebox'; +import { State } from '../state'; +import { UserId } from '@shared/database/mixin/user'; -// need: pongPausedParam -> uid1 uid2 -// resp -> game_uid | ?error -// -// q - why does 'type PongHistoryResponse = MakeStaticResponse' why makestatic response? - -// required to game create -> uid1+2 const CreatePausedGameParam = Type.Object({ user1: Type.String({ description: '\'id\' | ' }), user2: Type.String({ description: '\'id\' | ' }), @@ -21,8 +15,8 @@ const CreatePausedGameResponse = { '200': typeResponse('success', 'createPausedGame.success', { gameId: Type.String({ description: 'gameId' }), }), - '404': typeResponse('failure', 'createPausedGame.generic.fail') -} + '404': typeResponse('failure', 'createPausedGame.generic.fail'), +}; type CreatePausedGameResponse = MakeStaticResponse; @@ -36,13 +30,13 @@ const route: FastifyPluginAsync = async (fastify): Promise => { operationId: 'pongCreatePauseGame', }, }, - async function (req, res) { - let resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId); + async function(req, res) { + const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId); - if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')) } + if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); } // else return (res.makeResponse(200, 'success', 'createPausedGame.success')); - } - ) + }, + ); }; export default route; \ No newline at end of file diff --git a/src/pong/src/routes/startPausedGame.ts b/src/pong/src/routes/startPausedGame.ts index 37cbb6a..ef2f1c2 100644 --- a/src/pong/src/routes/startPausedGame.ts +++ b/src/pong/src/routes/startPausedGame.ts @@ -1,8 +1,8 @@ -import { MakeStaticResponse, typeResponse } from "@shared/utils"; -import { FastifyPluginAsync } from "fastify"; -import Type, { Static } from "typebox"; -import { State } from "../state"; -import { PongGameId } from "@shared/database/mixin/pong"; +import { MakeStaticResponse, typeResponse } from '@shared/utils'; +import { FastifyPluginAsync } from 'fastify'; +import Type, { Static } from 'typebox'; +import { State } from '../state'; +import { PongGameId } from '@shared/database/mixin/pong'; const startPausedGameParam = Type.Object({ gameId: Type.String({ description: '\'id\' | ' }), @@ -12,8 +12,8 @@ type startPausedGameParam = Static; const startPausedGameResponse = { '200': typeResponse('success', 'startPausedGame.success', {}), - '404': typeResponse('failure', 'startPausedGame.no_such_game') -} + '404': typeResponse('failure', 'startPausedGame.no_such_game'), +}; type startPausedGameResponse = MakeStaticResponse; @@ -27,13 +27,13 @@ const route: FastifyPluginAsync = async (fastify): Promise => { operationId: 'pongstartPauseGame', }, }, - async function (req, res) { - let resp = State.startPausedGame(req.body.gameId as PongGameId); + async function(req, res) { + const resp = State.startPausedGame(req.body.gameId as PongGameId); - if (resp !== true) { return (res.makeResponse(404, 'failure', 'startPausedGame.generic.fail')) } + if (resp !== true) { return (res.makeResponse(404, 'failure', 'startPausedGame.generic.fail')); } // else return (res.makeResponse(200, 'success', 'startPausedGame.success')); - } - ) + }, + ); }; export default route; \ No newline at end of file diff --git a/src/pong/src/state.ts b/src/pong/src/state.ts index 7021287..feffdd7 100644 --- a/src/pong/src/state.ts +++ b/src/pong/src/state.ts @@ -104,8 +104,7 @@ class StateI { } public newPausedGame(suid1 : string, suid2 : string) : GameId | undefined { - if (!this.users.has(suid1 as UserId) || !this.users.has(suid2 as UserId)) - return (undefined); + if (!this.users.has(suid1 as UserId) || !this.users.has(suid2 as UserId)) { return (undefined); } const uid1 : UserId = suid1 as UserId; const uid2 : UserId = suid2 as UserId; const g = new Pong(uid1, uid2); @@ -120,13 +119,13 @@ class StateI { if (!this.games.has(g_id) || (game = this.games.get(g_id)) === undefined) { return (false); } game.rdy_timer = Date.now(); - - let id1 = game.userLeft; - let id2 = game.userRight; + + const id1 = game.userLeft; + const id2 = game.userRight; if (!this.users.has(id1) || !this.users.has(id2)) { return (false); } - let usr1 = this.users.get(id1); - let usr2 = this.users.get(id2); + const usr1 = this.users.get(id1); + const usr2 = this.users.get(id2); if (isNullish(usr1) || isNullish(usr2)) { return (false); } const iState: GameUpdate = StateI.getGameUpdateData(g_id, game);