Enhance permission validation and error handling in permissionController
Updated the getUserPermissions function to include validation for clubId, ensuring it is a valid positive integer. Added error handling to return a 400 status with a descriptive message for invalid club IDs, improving the robustness of the API response.
This commit is contained in:
@@ -8,7 +8,13 @@ export const getUserPermissions = async (req, res) => {
|
||||
const { clubId } = req.params;
|
||||
const userId = req.user.id;
|
||||
|
||||
const permissions = await permissionService.getUserClubPermissions(userId, parseInt(clubId));
|
||||
// Validierung: clubId muss eine gültige Zahl sein
|
||||
const parsedClubId = parseInt(clubId, 10);
|
||||
if (isNaN(parsedClubId) || parsedClubId <= 0) {
|
||||
return res.status(400).json({ error: 'Ungültige Club-ID' });
|
||||
}
|
||||
|
||||
const permissions = await permissionService.getUserClubPermissions(userId, parsedClubId);
|
||||
|
||||
if (!permissions) {
|
||||
return res.status(404).json({ error: 'Keine Berechtigungen gefunden' });
|
||||
|
||||
Reference in New Issue
Block a user