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 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;

View file

@ -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<typeof PongHistoryResponse>' why makestatic response?
// required to game create -> uid1+2
const CreatePausedGameParam = Type.Object({
user1: Type.String({ description: '\'id\' | <userid>' }),
user2: Type.String({ description: '\'id\' | <userid>' }),
@ -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<typeof CreatePausedGameResponse>;
@ -36,13 +30,13 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
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;

View file

@ -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\' | <gameid>' }),
@ -12,8 +12,8 @@ type startPausedGameParam = Static<typeof startPausedGameParam>;
const startPausedGameResponse = {
'200': typeResponse('success', 'startPausedGame.success', {}),
'404': typeResponse('failure', 'startPausedGame.no_such_game')
}
'404': typeResponse('failure', 'startPausedGame.no_such_game'),
};
type startPausedGameResponse = MakeStaticResponse<typeof startPausedGameResponse>;
@ -27,13 +27,13 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
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;

View file

@ -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);