import { Request, Response, NextFunction } from 'express' import { ZodSchema } from 'zod' import { ApiError } from '../helpers/api-error.helper' export const validateBody = (schema: ZodSchema) => (request: Request, _res: Response, next: NextFunction): void => { const { success, error, data } = schema.safeParse(request.body) if (!success) throw new ApiError(400, 'Validation failed', error.format()) request.body = data next() } export const validateQueryParams = (schema: ZodSchema) => (request: Request, _res: Response, next: NextFunction): void => { const { success, error, data } = schema.safeParse(request.query) if (!success) throw new ApiError(400, 'Validation failed', error.format()) request.query = data next() }