backend: Update validation error messages and add room ID validation middleware
This commit is contained in:
parent
990f23f7b2
commit
546e17f1e5
@ -17,7 +17,7 @@ export const validateLoginRequest = (req: Request, res: Response, next: NextFunc
|
||||
|
||||
return res.status(422).json({
|
||||
error: 'Unprocessable Entity',
|
||||
message: 'Invalid request body',
|
||||
message: 'Invalid request',
|
||||
details: errors
|
||||
});
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ const rejectRequest = (res: Response, error: z.ZodError) => {
|
||||
|
||||
return res.status(422).json({
|
||||
error: 'Unprocessable Entity',
|
||||
message: 'Invalid request body',
|
||||
message: 'Invalid request',
|
||||
details: errors
|
||||
});
|
||||
};
|
||||
|
||||
@ -75,7 +75,7 @@ const rejectRequest = (res: Response, error: z.ZodError) => {
|
||||
|
||||
return res.status(422).json({
|
||||
error: 'Unprocessable Entity',
|
||||
message: 'Invalid request body',
|
||||
message: 'Invalid request',
|
||||
details: errors
|
||||
});
|
||||
};
|
||||
|
||||
@ -110,7 +110,7 @@ const rejectRequest = (res: Response, error: z.ZodError) => {
|
||||
|
||||
return res.status(422).json({
|
||||
error: 'Unprocessable Entity',
|
||||
message: 'Invalid request body',
|
||||
message: 'Invalid request',
|
||||
details: errors
|
||||
});
|
||||
};
|
||||
|
||||
@ -101,7 +101,7 @@ const BulkDeleteRoomsSchema = z.object({
|
||||
|
||||
return arg;
|
||||
},
|
||||
z.array(nonEmptySanitizedString('recordingId')).default([])
|
||||
z.array(nonEmptySanitizedString('roomId')).default([])
|
||||
)
|
||||
});
|
||||
|
||||
@ -142,6 +142,17 @@ export const withValidRoomPreferences = (req: Request, res: Response, next: Next
|
||||
next();
|
||||
};
|
||||
|
||||
export const withValidRoomId = (req: Request, res: Response, next: NextFunction) => {
|
||||
const { success, error, data } = nonEmptySanitizedString('roomId').safeParse(req.params.roomId);
|
||||
|
||||
if (!success) {
|
||||
return rejectRequest(res, error);
|
||||
}
|
||||
|
||||
req.params.roomId = data;
|
||||
next();
|
||||
};
|
||||
|
||||
export const withValidRoomBulkDeleteRequest = (req: Request, res: Response, next: NextFunction) => {
|
||||
const { success, error, data } = BulkDeleteRoomsSchema.safeParse(req.query);
|
||||
|
||||
@ -172,7 +183,7 @@ const rejectRequest = (res: Response, error: z.ZodError) => {
|
||||
|
||||
return res.status(422).json({
|
||||
error: 'Unprocessable Entity',
|
||||
message: 'Invalid request body',
|
||||
message: 'Invalid request',
|
||||
details: errors
|
||||
});
|
||||
};
|
||||
|
||||
@ -12,7 +12,8 @@ import {
|
||||
configureCreateRoomAuth,
|
||||
configureRoomAuthorization,
|
||||
withValidRoomPreferences,
|
||||
withValidRoomBulkDeleteRequest
|
||||
withValidRoomBulkDeleteRequest,
|
||||
withValidRoomId
|
||||
} from '../middlewares/index.js';
|
||||
|
||||
import { UserRole } from '@typings-ce';
|
||||
@ -39,6 +40,7 @@ roomRouter.get(
|
||||
'/:roomId',
|
||||
withAuth(apiKeyValidator, tokenAndRoleValidator(UserRole.ADMIN), participantTokenValidator),
|
||||
configureRoomAuthorization,
|
||||
withValidRoomId,
|
||||
roomCtrl.getRoom
|
||||
);
|
||||
roomRouter.delete('/:roomId', withAuth(apiKeyValidator, tokenAndRoleValidator(UserRole.ADMIN)), roomCtrl.deleteRoom);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user