nestjs-components
nestjs-components copied to clipboard
How to validate EmittedMessage payload with DTO? Validation is not working for me.
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.
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!
Thank you @ccoeurderoy
@ccoeurderoy Can you plz share the issue link, I am unable to find it in the nestjs issues.
Hey @gitSambhal, sorry I've transferred it to the @algoan/nestjs-components repository!
@ccoeurderoy kindly share the link.
@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.
Oh ok, now I understood. I forgot that it was in algoan/pubsub. Thanks.
Any update on this issue?
@samuelsweet I am now using Joi schema validation for validation the schema. No updates on this issue.
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 😕
Hi @ccoeurderoy I am using Joi library for validation instead of DTOs.