improved helpers system
This commit is contained in:
parent
54aeaa5bb3
commit
bbaa7dca35
5 changed files with 343 additions and 24 deletions
|
@ -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"});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue