From 7ab278c1afb2e0833b496a4956097542cb07b1d6 Mon Sep 17 00:00:00 2001 From: adjoly Date: Fri, 24 Oct 2025 15:21:33 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user/pMatchHistory.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/user/pMatchHistory.js b/src/api/user/pMatchHistory.js index 94dd63b..eb60871 100644 --- a/src/api/user/pMatchHistory.js +++ b/src/api/user/pMatchHistory.js @@ -3,9 +3,13 @@ const score_url = process.env.SCORE_URL || "http://localhost:3003"; async function fetchSave(request, reply, userId, addMatch) { let opponentName = ''; let opponentScore = 0; - if (request.body.opponent && request.body.opponentScore) { + if (request.body.opponent) { opponentName = request.body.opponent; + } + if (request.body.opponentScore !== undefined) { opponentScore = request.body.opponentScore; + } else { + opponentScore = 0; } const res = await fetch(score_url + "/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ p1: userId, p2: opponentName, p1Score: request.body.myScore, p2Score: opponentScore }) }); if (!res.ok) { @@ -27,7 +31,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat if (request.body.game !== 'pong' && request.body.game !== 'tetris') { return reply.code(400).send({ error: "Specified game does not exist" }); } - if (request.body.game === 'pong' && (!request.body.opponent || !request.body.opponentScore)) { + if (request.body.game === 'pong' && !request.body.opponent) { return reply.code(400).send({ error: "Game requires two players" }); } if (!getUserInfo.get(userId)) { @@ -41,7 +45,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat return reply.code(400).send({ error: "Do you have dementia ? You cannot have played a match against yourself gramps" }); } } - await fetchSave(request, reply, userId, addMatch); + fetchSave(request, reply, userId, addMatch); if (request.body.game === 'pong') { if (request.body.myScore > request.body.opponentScore) { incWinsPong.run(userId);