init
This commit is contained in:
32
src/routes/api/getGameScore.js
Normal file
32
src/routes/api/getGameScore.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const mysql = require("mysql2");
|
||||
const getGameScore = (req, res) => {
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.MARIA_HOST,
|
||||
user: process.env.MARIA_USER,
|
||||
password: process.env.MARIA_PASS,
|
||||
database: 'beanstalk_game',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
});
|
||||
const promisePool = pool.promise();
|
||||
const { userId, gameName, gameID } = req.body;
|
||||
|
||||
const query = 'SELECT score, gameTime FROM gameData WHERE userId = ? AND gameName = ? AND gameID = ?';
|
||||
|
||||
pool.query(query, [userId, gameName, gameID], (error, results) => {
|
||||
if (error) {
|
||||
return res.status(500).json({ message: 'Database query failed', error });
|
||||
}
|
||||
|
||||
if (results.length > 0) {
|
||||
const game = results[0];
|
||||
res.json({ score: game.score, gameTime: game.gameTime });
|
||||
} else {
|
||||
res.status(404).json({ message: 'Game data not found' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = getGameScore;
|
||||
|
||||
Reference in New Issue
Block a user