Как использовать отправку запросов с валидацией Celebrate Joi с Express Router? - PullRequest
0 голосов
/ 20 января 2020

enter image description here Я пытаюсь проверить маршрут ниже с почтальоном, но получаю указанную ниже ошибку. Я не уверен, что я делаю неправильно. В Почтальон я помещаю данные в сыром виде. Мне нужна помощь с этим. Спасибо!

app.use('/auth', route);

  route.post(
    '/signup',
    celebrate({
      body: Joi.object({
        name: Joi.string().required(),
        email: Joi.string().required(),
        password: Joi.string().required(),
      }),
    }),
    async (req: Request, res: Response, next: NextFunction) => {
      const logger = Container.get('logger') as winston.Logger;
      logger.debug('Calling Sign-Up endpoint with body: %o', req.body )
      try {
        const authServiceInstance = Container.get(AuthService);
        console.log(authServiceInstance)
        const { user, token } = await authServiceInstance.SignUp(req.body as IUserInputDTO);
        console.log(user, token)
        return res.status(201).json({ user, token });
      } catch (e) {
        logger.error('error: %o', e);
        return next(e);
      }
    },
  );

Я получаю эту ошибку:

{
    "errors": {
        "message": "child \"name\" fails because [\"name\" is required]"
    }
}

при попытке использовать JSON в качестве тестового входа в JSON

{
    "name": "Test",
    "email": "test@mail.com",
    "password": "123abc"
}

userInputDTO выглядит следующим образом

export interface IUserInputDTO {
  name: string;
  email: string;
  password: string;
}

это пост почтальона

http://localhost: 3000 / api / auth / signup

...