This commit is contained in:
Lukian 2024-09-17 14:05:54 +02:00
parent 5bb9a27e3c
commit afc5217d0a

View file

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