import { MiddlewareFunction , BadRequestException } from '@nestjs/common' ; import { Request , Response } from 'express' ; import { validate } from 'joi' ; import { authUserSchema } from '../../users/joi/auth-user.joi' ; export const bodyValidatorMiddleware = async ( req , res , next ) => { const result = validate ( req . body , authUserSchema ) ; if ( result . error ) { const errorMessage = result . error . details . shift ( ) . message ; const message = errorMessage . replace ( /["]/g , '' ) ; return next ( new BadRequestException ( `Validation failed: ${ message }` ) ) ; } next ( ) ; } ;