This commit is contained in:
Marces Zastrow
2025-01-17 14:12:07 +01:00
parent 6f52b6ffb0
commit 5fa7a56a53
4 changed files with 35 additions and 35 deletions
Binary file not shown.
+5 -2
View File
@@ -166,12 +166,15 @@ app.post('/games', (req, res) => {
app.post('/createGame', (req, res) => {
const { name, description, gameMasterId, participants } = req.body;
const gameId = crypto.randomBytes(4).toString('hex');
const gameId = crypto.randomBytes(4).toString('hex');
// Convert gameMasterId to integer
const parsedGameMasterId = parseInt(gameMasterId);
const stmt = db.prepare('INSERT INTO games (game_id, name, description, game_master_id, participants) VALUES (?, ?, ?, ?, ?)');
stmt.run([gameId, name, description, gameMasterId, JSON.stringify(participants)], function (err) {
stmt.run([gameId, name, description, parsedGameMasterId, JSON.stringify(participants)], function (err) {
if (err) {
console.error('Database error:', err);
return res.status(400).json({ error: 'Failed to create game.' });
}
res.status(201).json({ message: 'Game created successfully!', gameId: gameId });