This commit is contained in:
bgoulard 2026-01-09 11:14:16 +01:00 committed by Nigel
parent a65b8a9067
commit 8564088a3b
2 changed files with 26 additions and 25 deletions

View file

@ -33,15 +33,15 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
type: 'object',
required: ['nextGame'],
properties: {
nextGame: { type: 'string' }
}
}
}
nextGame: { type: 'string' },
},
},
},
}, async (req, reply) => {
const gameLink: Promise<string> = Promise.resolve(req.body as string);
if (gameLink)
if (gameLink) {
broadcastNextGame(fastify, gameLink);
}
return reply.send({ status: 'ok' });
});
};

View file

@ -205,19 +205,20 @@ class StateI {
this.fastify.db.setPongGameOutcome(gameId, { id: game.userLeft, score: game.score[0] }, { id: game.userRight, score: game.score[1] }, outcome, game.local);
this.fastify.log.info('SetGameOutcome !');
if (!game.local) {
let payload = {'nextGame':chat_text};
const payload = { 'nextGame':chat_text };
try {
const resp = await fetch("http://app-chat/api/chat/broadcast", {
const resp = await fetch('http://app-chat/api/chat/broadcast', {
method:'POST',
headers:{ 'Content-type':'application/json' },
body: JSON.stringify(payload),
});
if (!resp.ok)
throw(resp);
else
this.fastify.log.info("game-end info to chat success");
} catch (e : any) {
if (!resp.ok) { throw (resp); }
else { this.fastify.log.info('game-end info to chat success'); }
}
// disable eslint for err catching
// eslint-disable-next-line @typescript-eslint/no-explicit-any
catch (e : any) {
this.fastify.log.error(`game-end info to chat failed: ${e}`);
}
}