Skip to content

How to use express-validator with inversify-express-utils #1114

@WandersonAlves

Description

@WandersonAlves

Context

Without inversify-express-utils i use express-validator (https://express-validator.github.io/docs/) like this:

const checkContext = [query('codusur').exists()];
router.get('/context', checkContext, (req: Request, res: Response, next: NextFunction) => {
  req.setTimeout(0, null);
  const errors = validationResult(req);

  if (!errors.isEmpty()) {
    next(new UnprocessableEntityException(errors.array()));
    return;
  }
  clientBusiness.getClientByVendor(req, res, next);
});

With inversify-express-utils i can't use express-validator

@httpGet('/', [query('id').exists()])
  @withException
  async getTenants(@response() res: Response) {
    const result = await this.tenantService.find({});
    res.status(OK).send(result);
  }

The code above throws a error:

Argument of type 'ValidationChain[]' is not assignable to parameter of type 'string | symbol | Newable | Abstract | RequestHandler'.
Type 'ValidationChain[]' is not assignable to type 'string'.

So the question is: how to use these type of middleware? I'm migrating some legacy code to inversifyjs and this is the last thing that i have to do

Your Environment

  • Versions used:
    "express-validator": "^5.2.0",
    "inversify": "^5.0.1",
    "inversify-express-utils": "^6.3.2"
    NodeJS: 10.15.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions