add: merged front with back
This commit is contained in:
parent
1832ed12ec
commit
48f50a1daa
42 changed files with 5458 additions and 20 deletions
36
back/api/v1/games/removeHelper.js
Normal file
36
back/api/v1/games/removeHelper.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
const express = require('express');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const { getConnection, removeHelper, getHelpers } = require("../../../libs/mysql.js")
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const {token, gameid} = req.body;
|
||||
|
||||
if (!token) {
|
||||
return res.status(400).send({error: "invalid token"});
|
||||
}
|
||||
|
||||
if (!gameid) {
|
||||
return res.status(400).send({error: "invalid gameid"});
|
||||
}
|
||||
|
||||
try {
|
||||
const user = jwt.verify(token, process.env.JWTSecret);
|
||||
|
||||
if (user.expiration < Date.now()) {
|
||||
return res.status(400).send({error: "token expired"});
|
||||
}
|
||||
|
||||
const connection = await getConnection();
|
||||
await removeHelper(connection, gameid, user.user.id)
|
||||
connection.end();
|
||||
} catch {
|
||||
return res.status(400).send({error: "invalid token"});
|
||||
}
|
||||
|
||||
res.status(200).send({message: "success"});
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue