Function validate

  • Description

    this function is used to validate the request body

    Example

    validate([body('email').isEmail(), body('password').isLength({ min: 5 })])
    

    Example

    example with controller

    export const login = [
    validate([body('email'), body('password')]),
    async (req: Request, res: Response) => {
    // do something
    }
    ]

    Example

    // example of error response email is not valid

    {
    "errors": [
    {
    "value": "test",
    "msg": "Invalid value",
    "param": "email",
    "location": "body"
    },
    ]

    Parameters

    • validations: any

    Returns ((req, res, next) => Promise<void>)

      • (req, res, next): Promise<void>
      • Parameters

        • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
        • res: Response<any, Record<string, any>>
        • next: NextFunction

        Returns Promise<void>

Generated using TypeDoc