From afc5217d0aa1ea6494761cb0caa9ed3f691bbe2d Mon Sep 17 00:00:00 2001 From: Lukian Date: Tue, 17 Sep 2024 14:05:54 +0200 Subject: [PATCH] bug fix --- api/v1/games/addHelper.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/v1/games/addHelper.js b/api/v1/games/addHelper.js index 4165bc8..0883eb5 100644 --- a/api/v1/games/addHelper.js +++ b/api/v1/games/addHelper.js @@ -1,7 +1,7 @@ const express = require('express'); const jwt = require('jsonwebtoken'); -const { getConnection, addHelper, getGame } = require("../../../libs/mysql.js") +const { getConnection, addHelper, getGame, getHelpers } = require("../../../libs/mysql.js") const router = express.Router(); @@ -24,18 +24,19 @@ router.post('/', async (req, res) => { } const connection = await getConnection(); - const game = await getGame(connection, gameid); if (!game[0]) { return res.status(400).send({error: "this game doesn't exist"}); } - if (JSON.parse(game[0].helpers).includes(user.user.username)) { + const helpers = await getHelpers(connection, gameid); + + if (JSON.stringify(helpers).includes(user.user.id)) { return res.status(400).send({error: "you are already an helper for this game"}); } - await addHelper(connection, user.user.username, gameid); + await addHelper(connection, gameid, user.user.id); connection.end(); } catch (error) { console.log(error);