Add meetings feature with admin-only CRUD
- Add meetings table with timezone support - Add meeting.service.js with timezone parsing (Europe/Bratislava) - Add meeting.controller.js for CRUD operations - Add meeting.routes.js with admin middleware for create/update/delete - GET endpoints available for all authenticated users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
90
src/routes/meeting.routes.js
Normal file
90
src/routes/meeting.routes.js
Normal file
@@ -0,0 +1,90 @@
|
||||
import express from 'express';
|
||||
import * as meetingController from '../controllers/meeting.controller.js';
|
||||
import { authenticate } from '../middlewares/auth/authMiddleware.js';
|
||||
import { requireAdmin } from '../middlewares/auth/roleMiddleware.js';
|
||||
import { validateBody, validateParams, validateQuery } from '../middlewares/security/validateInput.js';
|
||||
import { z } from 'zod';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Schema pre meeting
|
||||
const meetingSchema = z.object({
|
||||
title: z.string().min(1, 'Názov je povinný'),
|
||||
description: z.string().optional(),
|
||||
start: z.string().min(1, 'Začiatok je povinný'),
|
||||
end: z.string().min(1, 'Koniec je povinný'),
|
||||
});
|
||||
|
||||
const meetingUpdateSchema = z.object({
|
||||
title: z.string().min(1).optional(),
|
||||
description: z.string().optional(),
|
||||
start: z.string().optional(),
|
||||
end: z.string().optional(),
|
||||
});
|
||||
|
||||
const monthQuerySchema = z.object({
|
||||
year: z.string().regex(/^\d{4}$/).optional(),
|
||||
month: z.string().regex(/^(1[0-2]|[1-9])$/).optional(),
|
||||
});
|
||||
|
||||
const meetingIdSchema = z.object({
|
||||
meetingId: z.string().uuid(),
|
||||
});
|
||||
|
||||
// Všetky routes vyžadujú autentifikáciu
|
||||
router.use(authenticate);
|
||||
|
||||
/**
|
||||
* GET /api/meetings - Získať meetingy podľa mesiaca (všetci autentifikovaní používatelia)
|
||||
*/
|
||||
router.get(
|
||||
'/',
|
||||
validateQuery(monthQuerySchema),
|
||||
meetingController.getMeetingsByMonth
|
||||
);
|
||||
|
||||
/**
|
||||
* GET /api/meetings/:meetingId - Získať konkrétny meeting (všetci autentifikovaní používatelia)
|
||||
*/
|
||||
router.get(
|
||||
'/:meetingId',
|
||||
validateParams(meetingIdSchema),
|
||||
meetingController.getMeetingById
|
||||
);
|
||||
|
||||
/**
|
||||
* Admin-only routes (CREATE, UPDATE, DELETE)
|
||||
*/
|
||||
|
||||
/**
|
||||
* POST /api/meetings - Vytvoriť meeting (iba admin)
|
||||
*/
|
||||
router.post(
|
||||
'/',
|
||||
requireAdmin,
|
||||
validateBody(meetingSchema),
|
||||
meetingController.createMeeting
|
||||
);
|
||||
|
||||
/**
|
||||
* PUT /api/meetings/:meetingId - Upraviť meeting (iba admin)
|
||||
*/
|
||||
router.put(
|
||||
'/:meetingId',
|
||||
requireAdmin,
|
||||
validateParams(meetingIdSchema),
|
||||
validateBody(meetingUpdateSchema),
|
||||
meetingController.updateMeeting
|
||||
);
|
||||
|
||||
/**
|
||||
* DELETE /api/meetings/:meetingId - Zmazať meeting (iba admin)
|
||||
*/
|
||||
router.delete(
|
||||
'/:meetingId',
|
||||
requireAdmin,
|
||||
validateParams(meetingIdSchema),
|
||||
meetingController.deleteMeeting
|
||||
);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user