Add timefix and vacation routes to backend; update frontend for new routes and page titles

This commit is contained in:
Torsten Schulz (local)
2025-10-17 15:54:30 +02:00
parent e95bb4cb76
commit b65a13d815
16 changed files with 1913 additions and 13 deletions

View File

@@ -0,0 +1,73 @@
const vacationService = require('../services/VacationService');
class VacationController {
/**
* Holt alle Urlaubseinträge für einen User
*/
async getAllVacations(req, res) {
try {
const userId = req.user.userId;
const vacations = await vacationService.getAllVacations(userId);
res.json(vacations);
} catch (error) {
console.error('Fehler beim Abrufen der Urlaubseinträge:', error);
res.status(500).json({
message: 'Fehler beim Abrufen der Urlaubseinträge',
error: error.message
});
}
}
/**
* Erstellt einen neuen Urlaubseintrag
*/
async createVacation(req, res) {
try {
const userId = req.user.userId;
const { vacationType, startDate, endDate } = req.body;
if (vacationType === undefined || !startDate) {
return res.status(400).json({
message: 'Fehlende Pflichtfelder: vacationType, startDate'
});
}
const vacation = await vacationService.createVacation(userId, vacationType, startDate, endDate);
res.status(201).json({
message: 'Urlaubseintrag erfolgreich erstellt',
vacation
});
} catch (error) {
console.error('Fehler beim Erstellen des Urlaubseintrags:', error);
res.status(500).json({
message: 'Fehler beim Erstellen des Urlaubseintrags',
error: error.message
});
}
}
/**
* Löscht einen Urlaubseintrag
*/
async deleteVacation(req, res) {
try {
const userId = req.user.userId;
const vacationId = req.params.id;
console.log('DEBUG deleteVacation: vacationId =', vacationId, 'type =', typeof vacationId);
await vacationService.deleteVacation(userId, vacationId);
res.json({ message: 'Urlaubseintrag erfolgreich gelöscht' });
} catch (error) {
console.error('Fehler beim Löschen des Urlaubseintrags:', error);
res.status(500).json({
message: 'Fehler beim Löschen des Urlaubseintrags',
error: error.message
});
}
}
}
module.exports = new VacationController();