Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to validate EmittedMessage payload with DTO? Validation is not working for me. #517

Open
gitSambhal opened this issue Aug 31, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@gitSambhal
Copy link

Hi I want to validate the EmittedMessage using the DTO but the validation is not working. I am using Google Pubsub microservice.

export class OrderDTO {
  @IsString()
  @IsNotEmpty()
  public id: string;

   ...
}
@EventPattern(PS_SUBSCRIPTION_EVENTS.CREATE_ORDER_SUBSCRIBE)
  public async handleOrderReceivedFromCustomer(
    @Payload(ValidationPipe)
    data: EmittedMessage<OrderDTO>,
  ): Promise<void> {
    const order = <OrderDTO>data.payload;
    // Do something
}

I have added global validation pipe, tried with controller/param level validation pipes using @UsePipes but still it goes inside the consoller function without throwing the error if I send the empty object in Google Pubsub event data.

@ccoeurderoy ccoeurderoy transferred this issue from algoan/pubsub Sep 1, 2022
@ccoeurderoy
Copy link
Contributor

ccoeurderoy commented Sep 1, 2022

Hey @gitSambhal I've transferred your issue to the correct repository since it is related to the nestjs-components repo. I have a look at it as soon as I can!

@ccoeurderoy ccoeurderoy added the bug Something isn't working label Sep 1, 2022
@gitSambhal
Copy link
Author

Thank you @ccoeurderoy

@gitSambhal
Copy link
Author

@ccoeurderoy Can you plz share the issue link, I am unable to find it in the nestjs issues.

@ccoeurderoy
Copy link
Contributor

Hey @gitSambhal, sorry I've transferred it to the @algoan/nestjs-components repository!

@gitSambhal
Copy link
Author

@ccoeurderoy kindly share the link.

@ccoeurderoy
Copy link
Contributor

ccoeurderoy commented Sep 5, 2022

@gitSambhal this is the transferred issue 😅 You've opened it in algoan/pubsub repository and now, it is opened in nestjs-components repo.

I've moved into this repo because it is related to nestjs-google-pubsub-microservice lib, not algoan/pubsub.

@gitSambhal
Copy link
Author

Oh ok, now I understood. I forgot that it was in algoan/pubsub. Thanks.

@samuelsweet
Copy link
Contributor

Any update on this issue?

@gitSambhal
Copy link
Author

gitSambhal commented Sep 17, 2022

@samuelsweet I am now using Joi schema validation for validation the schema. No updates on this issue.

@ccoeurderoy
Copy link
Contributor

Hey guys, since the EmittedMessage is not a DTO class, the native NestJS validation pipe cannot work (I could be wrong).

But it could be great to add an option in order to validate the emitted payload property. However, I cannot tell you when it will be done 😕

@gitSambhal
Copy link
Author

Hi @ccoeurderoy
I am using Joi library for validation instead of DTOs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants