k
This commit is contained in:
Binary file not shown.
+5
-2
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user