firt commit
This commit is contained in:
commit
c2e63830e1
71 changed files with 9613 additions and 0 deletions
32
server/routes/admin.js
Executable file
32
server/routes/admin.js
Executable file
|
@ -0,0 +1,32 @@
|
|||
import express from 'express';
|
||||
import multer from 'multer';
|
||||
import { addMatch, deleteMatch } from '../controllers/adminController.js'; // Assuming this controller file/function
|
||||
import { checkPassword, setPassword, verifyPassword } from '../controllers/authController.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Set up multer for file uploads
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, './public/uploads/'); // Directory for uploaded files
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
cb(null, `${Date.now()}-${file.originalname}`);
|
||||
}
|
||||
});
|
||||
const upload = multer({ storage: storage });
|
||||
|
||||
// Admin authentication routes
|
||||
router.get('/check-password', checkPassword);
|
||||
router.post('/set-password', setPassword);
|
||||
router.post('/verify-password', verifyPassword);
|
||||
|
||||
// Route to add a new match
|
||||
router.post('/matches', upload.array('pdfFiles'), addMatch);
|
||||
|
||||
// Route to delete a match
|
||||
router.delete('/matches/:id', deleteMatch);
|
||||
|
||||
// Add other admin routes here later (e.g., for status page)
|
||||
|
||||
export default router;
|
12
server/routes/matches.js
Executable file
12
server/routes/matches.js
Executable file
|
@ -0,0 +1,12 @@
|
|||
import express from 'express';
|
||||
import { getMatches, getMatchDetails } from '../controllers/matchController.js'; // Assuming this controller file/functions
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Route to get all matches
|
||||
router.get('/', getMatches);
|
||||
|
||||
// Route to get details for a specific match
|
||||
router.get('/:id', getMatchDetails);
|
||||
|
||||
export default router;
|
82
server/routes/tickets.js
Executable file
82
server/routes/tickets.js
Executable file
|
@ -0,0 +1,82 @@
|
|||
import express from 'express';
|
||||
import { createTicket, getTicketStatus, getMatchSeats } from '../controllers/ticketController.js';
|
||||
import multer from 'multer';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Configure multer for file uploads
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
cb(null, path.join(__dirname, '../uploads'));
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
|
||||
cb(null, uniqueSuffix + path.extname(file.originalname));
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
fileFilter: (req, file, cb) => {
|
||||
if (file.mimetype === 'application/pdf') {
|
||||
cb(null, true);
|
||||
} else {
|
||||
cb(new Error('Only PDF files are allowed'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new ticket
|
||||
router.post('/', upload.single('pdfFile'), async (req, res) => {
|
||||
try {
|
||||
const { matchId, name, email, phone, seats, deliveryMethod } = req.body;
|
||||
const pdfFile = req.file;
|
||||
|
||||
if (!matchId || !name || !email || !phone || !seats || !deliveryMethod) {
|
||||
return res.status(400).json({ message: 'Missing required fields' });
|
||||
}
|
||||
|
||||
if (deliveryMethod === 'email' && !email) {
|
||||
return res.status(400).json({ message: 'Email is required for email delivery' });
|
||||
}
|
||||
|
||||
const ticket = await createTicket({
|
||||
matchId,
|
||||
name,
|
||||
email,
|
||||
phone,
|
||||
seats: parseInt(seats),
|
||||
pdfFile: pdfFile ? pdfFile.filename : null,
|
||||
deliveryMethod
|
||||
});
|
||||
|
||||
res.status(201).json(ticket);
|
||||
} catch (error) {
|
||||
console.error('Error creating ticket:', error);
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get ticket status
|
||||
router.get('/:ticketId', async (req, res) => {
|
||||
try {
|
||||
const ticket = await getTicketStatus(req.params.ticketId);
|
||||
if (!ticket) {
|
||||
return res.status(404).json({ message: 'Ticket not found' });
|
||||
}
|
||||
res.json(ticket);
|
||||
} catch (error) {
|
||||
console.error('Error getting ticket status:', error);
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get seats for a match
|
||||
router.get('/match/:matchId/seats', getMatchSeats);
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue