eslint on api for paused games

This commit is contained in:
bgoulard 2026-01-10 17:13:42 +01:00 committed by Maix0
parent ce02e37b81
commit 3c95af8ede
4 changed files with 31 additions and 38 deletions

View file

@ -132,7 +132,7 @@ export class Pong {
public sendSig : boolean = false; public sendSig : boolean = false;
public ready_checks: [boolean, boolean] = [false, 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 score: [number, number] = [0, 0];
public local: boolean = false; public local: boolean = false;

View file

@ -1,15 +1,9 @@
import { isNullish, MakeStaticResponse, typeResponse } from "@shared/utils"; import { isNullish, MakeStaticResponse, typeResponse } from '@shared/utils';
import { FastifyPluginAsync } from "fastify"; import { FastifyPluginAsync } from 'fastify';
import { Static, Type } from "typebox"; import { Static, Type } from 'typebox';
import { State } from "../state"; import { State } from '../state';
import { UserId } from "@shared/database/mixin/user"; import { UserId } from '@shared/database/mixin/user';
// need: pongPausedParam -> uid1 uid2
// resp -> game_uid | ?error
//
// q - why does 'type PongHistoryResponse = MakeStaticResponse<typeof PongHistoryResponse>' why makestatic response?
// required to game create -> uid1+2
const CreatePausedGameParam = Type.Object({ const CreatePausedGameParam = Type.Object({
user1: Type.String({ description: '\'id\' | <userid>' }), user1: Type.String({ description: '\'id\' | <userid>' }),
user2: Type.String({ description: '\'id\' | <userid>' }), user2: Type.String({ description: '\'id\' | <userid>' }),
@ -21,8 +15,8 @@ const CreatePausedGameResponse = {
'200': typeResponse('success', 'createPausedGame.success', { '200': typeResponse('success', 'createPausedGame.success', {
gameId: Type.String({ description: 'gameId' }), gameId: Type.String({ description: 'gameId' }),
}), }),
'404': typeResponse('failure', 'createPausedGame.generic.fail') '404': typeResponse('failure', 'createPausedGame.generic.fail'),
} };
type CreatePausedGameResponse = MakeStaticResponse<typeof CreatePausedGameResponse>; type CreatePausedGameResponse = MakeStaticResponse<typeof CreatePausedGameResponse>;
@ -36,13 +30,13 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
operationId: 'pongCreatePauseGame', operationId: 'pongCreatePauseGame',
}, },
}, },
async function (req, res) { async function(req, res) {
let resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId); 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 // else
return (res.makeResponse(200, 'success', 'createPausedGame.success')); return (res.makeResponse(200, 'success', 'createPausedGame.success'));
} },
) );
}; };
export default route; export default route;

View file

@ -1,8 +1,8 @@
import { MakeStaticResponse, typeResponse } from "@shared/utils"; import { MakeStaticResponse, typeResponse } from '@shared/utils';
import { FastifyPluginAsync } from "fastify"; import { FastifyPluginAsync } from 'fastify';
import Type, { Static } from "typebox"; import Type, { Static } from 'typebox';
import { State } from "../state"; import { State } from '../state';
import { PongGameId } from "@shared/database/mixin/pong"; import { PongGameId } from '@shared/database/mixin/pong';
const startPausedGameParam = Type.Object({ const startPausedGameParam = Type.Object({
gameId: Type.String({ description: '\'id\' | <gameid>' }), gameId: Type.String({ description: '\'id\' | <gameid>' }),
@ -12,8 +12,8 @@ type startPausedGameParam = Static<typeof startPausedGameParam>;
const startPausedGameResponse = { const startPausedGameResponse = {
'200': typeResponse('success', 'startPausedGame.success', {}), '200': typeResponse('success', 'startPausedGame.success', {}),
'404': typeResponse('failure', 'startPausedGame.no_such_game') '404': typeResponse('failure', 'startPausedGame.no_such_game'),
} };
type startPausedGameResponse = MakeStaticResponse<typeof startPausedGameResponse>; type startPausedGameResponse = MakeStaticResponse<typeof startPausedGameResponse>;
@ -27,13 +27,13 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
operationId: 'pongstartPauseGame', operationId: 'pongstartPauseGame',
}, },
}, },
async function (req, res) { async function(req, res) {
let resp = State.startPausedGame(req.body.gameId as PongGameId); 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 // else
return (res.makeResponse(200, 'success', 'startPausedGame.success')); return (res.makeResponse(200, 'success', 'startPausedGame.success'));
} },
) );
}; };
export default route; export default route;

View file

@ -104,8 +104,7 @@ class StateI {
} }
public newPausedGame(suid1 : string, suid2 : string) : GameId | undefined { public newPausedGame(suid1 : string, suid2 : string) : GameId | undefined {
if (!this.users.has(suid1 as UserId) || !this.users.has(suid2 as UserId)) if (!this.users.has(suid1 as UserId) || !this.users.has(suid2 as UserId)) { return (undefined); }
return (undefined);
const uid1 : UserId = suid1 as UserId; const uid1 : UserId = suid1 as UserId;
const uid2 : UserId = suid2 as UserId; const uid2 : UserId = suid2 as UserId;
const g = new Pong(uid1, uid2); const g = new Pong(uid1, uid2);
@ -121,12 +120,12 @@ class StateI {
if (!this.games.has(g_id) || (game = this.games.get(g_id)) === undefined) { return (false); } if (!this.games.has(g_id) || (game = this.games.get(g_id)) === undefined) { return (false); }
game.rdy_timer = Date.now(); game.rdy_timer = Date.now();
let id1 = game.userLeft; const id1 = game.userLeft;
let id2 = game.userRight; const id2 = game.userRight;
if (!this.users.has(id1) || !this.users.has(id2)) { return (false); } if (!this.users.has(id1) || !this.users.has(id2)) { return (false); }
let usr1 = this.users.get(id1); const usr1 = this.users.get(id1);
let usr2 = this.users.get(id2); const usr2 = this.users.get(id2);
if (isNullish(usr1) || isNullish(usr2)) { return (false); } if (isNullish(usr1) || isNullish(usr2)) { return (false); }
const iState: GameUpdate = StateI.getGameUpdateData(g_id, game); const iState: GameUpdate = StateI.getGameUpdateData(g_id, game);