Files
crm-server/src/controllers/meeting.controller.js
richardtekula 6f4a31e9de Code quality improvements from code review
- Add admin-only authorization for company and projects CRUD operations
- Create requireAccountId middleware to eliminate code duplication
- Standardize error handling (use next(error) consistently)
- Change error messages to Slovak language

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 11:03:32 +01:00

106 lines
2.2 KiB
JavaScript

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);
}
};