Add invite routes to backend and frontend; implement routing and UI components for invitation management
This commit is contained in:
63
backend/src/controllers/InviteController.js
Normal file
63
backend/src/controllers/InviteController.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const InviteService = require('../services/InviteService');
|
||||
|
||||
/**
|
||||
* Controller für Einladungen
|
||||
* Verarbeitet HTTP-Requests und delegiert an InviteService
|
||||
*/
|
||||
class InviteController {
|
||||
/**
|
||||
* Sendet eine Einladung
|
||||
*/
|
||||
async sendInvite(req, res) {
|
||||
try {
|
||||
const userId = req.user?.id || 1;
|
||||
const { email } = req.body;
|
||||
|
||||
if (!email) {
|
||||
return res.status(400).json({
|
||||
message: 'Email-Adresse ist erforderlich'
|
||||
});
|
||||
}
|
||||
|
||||
const invitation = await InviteService.sendInvite(userId, email);
|
||||
res.status(201).json(invitation);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Senden der Einladung:', error);
|
||||
|
||||
// Spezifische Fehlermeldungen
|
||||
if (error.message.includes('bereits eingeladen')) {
|
||||
return res.status(429).json({ message: error.message }); // Too Many Requests
|
||||
}
|
||||
|
||||
if (error.message.includes('bereits registriert')) {
|
||||
return res.status(409).json({ message: error.message }); // Conflict
|
||||
}
|
||||
|
||||
res.status(500).json({
|
||||
message: error.message || 'Fehler beim Senden der Einladung'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle Einladungen des aktuellen Users
|
||||
*/
|
||||
async getMyInvitations(req, res) {
|
||||
try {
|
||||
const userId = req.user?.id || 1;
|
||||
const activeOnly = req.query.activeOnly === 'true';
|
||||
|
||||
const invitations = await InviteService.getUserInvitations(userId, activeOnly);
|
||||
res.json(invitations);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Einladungen:', error);
|
||||
res.status(500).json({
|
||||
message: 'Fehler beim Abrufen der Einladungen',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new InviteController();
|
||||
|
||||
Reference in New Issue
Block a user