feat: Replace Meetings with Calendar - events with types and assigned users

- Rename meetings table to events with type field (meeting/event)
- Add eventUsers junction table for user assignments
- Members see only events they're assigned to
- Calendar endpoint returns events + todos for month
- Add migration SQL for database changes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
richardtekula
2025-12-15 10:50:31 +01:00
parent f828af562d
commit 3eb2f6ea02
10 changed files with 589 additions and 362 deletions

View File

@@ -0,0 +1,108 @@
import * as eventService from '../services/event.service.js';
/**
* Get calendar data (events + todos) by month
* GET /api/events?year=2024&month=1
*/
export const getCalendarData = async (req, res, next) => {
try {
const { year, month } = req.query;
const userId = req.userId;
const isAdmin = req.user?.role === 'admin';
const currentDate = new Date();
const queryYear = year ? parseInt(year) : currentDate.getFullYear();
const queryMonth = month ? parseInt(month) : currentDate.getMonth() + 1;
const data = await eventService.getCalendarData(queryYear, queryMonth, userId, isAdmin);
res.status(200).json({
success: true,
data,
});
} catch (error) {
next(error);
}
};
/**
* Get event by ID
* GET /api/events/:eventId
*/
export const getEventById = async (req, res, next) => {
try {
const { eventId } = req.params;
const userId = req.userId;
const isAdmin = req.user?.role === 'admin';
const event = await eventService.getEventById(eventId, userId, isAdmin);
res.status(200).json({
success: true,
data: event,
});
} catch (error) {
next(error);
}
};
/**
* Create a new event (admin only)
* POST /api/events
*/
export const createEvent = async (req, res, next) => {
try {
const userId = req.userId;
const data = req.body;
const event = await eventService.createEvent(userId, data);
res.status(201).json({
success: true,
data: event,
message: 'Event bol vytvorený',
});
} catch (error) {
next(error);
}
};
/**
* Update an event (admin only)
* PUT /api/events/:eventId
*/
export const updateEvent = async (req, res, next) => {
try {
const { eventId } = req.params;
const data = req.body;
const event = await eventService.updateEvent(eventId, data);
res.status(200).json({
success: true,
data: event,
message: 'Event bol upravený',
});
} catch (error) {
next(error);
}
};
/**
* Delete an event (admin only)
* DELETE /api/events/:eventId
*/
export const deleteEvent = async (req, res, next) => {
try {
const { eventId } = req.params;
const result = await eventService.deleteEvent(eventId);
res.status(200).json({
success: true,
message: result.message,
});
} catch (error) {
next(error);
}
};

View File

@@ -1,105 +0,0 @@
import * as meetingService from '../services/meeting.service.js';
/**
* Get meetings by month
* GET /api/meetings?year=2024&month=1
*/
export const getMeetingsByMonth = async (req, res, next) => {
try {
const { year, month } = req.query;
const currentDate = new Date();
const queryYear = year ? parseInt(year) : currentDate.getFullYear();
const queryMonth = month ? parseInt(month) : currentDate.getMonth() + 1;
const meetings = await meetingService.getMeetingsByMonth(queryYear, queryMonth);
res.status(200).json({
success: true,
count: meetings.length,
data: meetings,
});
} catch (error) {
next(error);
}
};
/**
* Get meeting by ID
* GET /api/meetings/:meetingId
*/
export const getMeetingById = async (req, res, next) => {
try {
const { meetingId } = req.params;
const meeting = await meetingService.getMeetingById(meetingId);
res.status(200).json({
success: true,
data: meeting,
});
} catch (error) {
next(error);
}
};
/**
* Create a new meeting (admin only)
* POST /api/meetings
*/
export const createMeeting = async (req, res, next) => {
try {
const userId = req.userId;
const data = req.body;
const meeting = await meetingService.createMeeting(userId, data);
res.status(201).json({
success: true,
data: meeting,
message: 'Meeting bol vytvorený',
});
} catch (error) {
next(error);
}
};
/**
* Update a meeting (admin only)
* PUT /api/meetings/:meetingId
*/
export const updateMeeting = async (req, res, next) => {
try {
const { meetingId } = req.params;
const data = req.body;
const meeting = await meetingService.updateMeeting(meetingId, data);
res.status(200).json({
success: true,
data: meeting,
message: 'Meeting bol upravený',
});
} catch (error) {
next(error);
}
};
/**
* Delete a meeting (admin only)
* DELETE /api/meetings/:meetingId
*/
export const deleteMeeting = async (req, res, next) => {
try {
const { meetingId } = req.params;
const result = await meetingService.deleteMeeting(meetingId);
res.status(200).json({
success: true,
message: result.message,
});
} catch (error) {
next(error);
}
};