blob: 19507153c7fb3470279aa2fa7ffb43b814cd8397 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import { prisma } from '../config/db';
import express from 'express';
export const handleCreateGame = async (req: express.Request, res: express.Response) => {
try {
if (!req.session.userId) {
return res.status(401).json({ error: 'Authentication required' });
}
if (req.session.userId !== 1){
return res.status(403).json({ error: 'Unauthorized. You are not the admin of this instance' });
}
const user = await prisma.user.findUnique({
where: { id: req.session.userId },
select: { id: true, username: true, email: true }
});
if (!user) {
req.session.destroy((err) => {
if (err) console.error('Session destroy error:', err);
});
return res.status(401).json({ error: 'Invalid session' });
}
const { gameInternalName, gameFormattedName, gameDescription } = req.body;
if (!gameInternalName || !gameFormattedName || !gameDescription) {
return res.status(400).json({ error: 'All fields are required' });
}
const success = await prisma.game.create({
data: {
internalName: gameInternalName,
formattedName: gameFormattedName,
description: gameDescription,
}
});
if (!success) {
console.log('Failed to create game:', success);
return res.status(500).json({ error: 'Failed to create game. Does it already exist?' });
}
return res.status(200).json({ message: 'Game created successfully' });
} catch (error) {
console.error('Game Creation error:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
|