From 2aa4016a0aec25e3ecdfc3d105c899b30ecd36f9 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Wed, 5 Jun 2024 15:37:06 +0200 Subject: [PATCH] commit --- api/v1/games/getGame.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 api/v1/games/getGame.js diff --git a/api/v1/games/getGame.js b/api/v1/games/getGame.js new file mode 100644 index 0000000..c96e067 --- /dev/null +++ b/api/v1/games/getGame.js @@ -0,0 +1,30 @@ +const express = require('express'); +const jwt = require('jsonwebtoken'); + +const {getGame} = 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"}); + } + + try { + jwt.verify(token, process.env.JWTSecret); + } catch { + return res.status(400).send({error: "invalid token"}); + } + + const game = await getGame(gameid) + + if (!game[0]) { + return res.status(400).send({error: "this game doesn't exist in the data base"}) + }; + + res.status(200).send(game[0]); +}); + +module.exports = router; \ No newline at end of file