47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
import express from 'express';
|
|
import { nanoid } from 'nanoid';
|
|
|
|
const router = express.Router();
|
|
|
|
// Создать новую игру
|
|
router.post('/create', (req, res) => {
|
|
try {
|
|
const gameCode = nanoid(6).toUpperCase();
|
|
const { teamName } = req.body;
|
|
|
|
const game = {
|
|
gameCode,
|
|
teams: [{
|
|
name: teamName,
|
|
score: 0,
|
|
players: []
|
|
}],
|
|
currentRound: 1,
|
|
usedQuestions: [],
|
|
status: 'waiting',
|
|
createdAt: new Date()
|
|
};
|
|
|
|
res.json({
|
|
success: true,
|
|
gameCode,
|
|
game
|
|
});
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
// Проверить существование игры
|
|
router.get('/:gameCode', (req, res) => {
|
|
try {
|
|
const { gameCode } = req.params;
|
|
// Проверка будет в Socket.io, т.к. игры хранятся в памяти
|
|
res.json({ exists: true });
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
export default router;
|