How to validate the fields when I am receiving Rabbitmq data?

Asked

Viewed 9 times

0

I’m developing a service using the Nestjs framework for data consumption that I get from a Rabbitmq queue. I understand that to validate the fields of an api just do the following:

 @Post()
 async adicionarContato(@Body() data: CriarContatoDto) {}

Thus the request date will pass the Dto class and validate using the parameters of the Validator-class.

But in my case, I’m getting the data from the rabbitmq and not from a post request.

How am I getting:

@MessagePattern('fila_teste')
    async adicionarContato(@Payload() data, @Ctx() context: RmqContext) {}

How I tried:

@MessagePattern('fila_teste')
    async adicionarContato(@Payload() data: CriarContatoDto, @Ctx() context: RmqContext) {}

Even if I receive the date in the same format as the post request, the validation does not work when I receive the data from the queue. Could someone explain to me why, and how I would solve this?

Note: I couldn’t use the Nestjs tag because it doesn’t exist yet and I don’t have enough reputation to create it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.