improved helpers system

This commit is contained in:
Lukian 2024-09-17 13:46:50 +02:00
parent 54aeaa5bb3
commit bbaa7dca35
5 changed files with 343 additions and 24 deletions

View file

@ -1,7 +1,7 @@
const express = require('express');
const jwt = require('jsonwebtoken');
const { getConnection, removeHelper, getGame } = require("../../../libs/mysql.js")
const { getConnection, removeHelper, getHelpers } = require("../../../libs/mysql.js")
const router = express.Router();
@ -24,18 +24,8 @@ 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)) {
return res.status(400).send({error: "you are not an helper for this game"});
}
await removeHelper(connection, user.user.username, gameid);
connection.end()
await removeHelper(connection, gameid, user.user.id)
connection.end();
} catch {
return res.status(400).send({error: "invalid token"});
}