【发布时间】:2022-01-08 14:06:24
【问题描述】:
我正在尝试发送直接函数调用,并设置了 DTO,但不起作用。 这是我控制器中的代码(发送是我的 DTO):
@Post('/Send')
async SendE(body: Send) {
const mail = await this.messageProducer.SendMessage(body);
return mail;
}
我在这里直接调用 SendE 函数:
@MessagePattern('Notification')
async readMessage(@Payload() message: any, @Ctx() context: KafkaContext) {
const messageString = JSON.stringify(context.getMessage().value);
const toJson = JSON.parse(messageString);
await this.SendE(toJson);
}
我希望“发送”DTO 可以验证“toJson”,但它不起作用。 这是我的 DTO 的样子:
export class Send{
@IsString()
@ApiProperty({ required: true })
MessageID: string;
}
这是 toJson 的样子:
{
MessageID: 123
}
如果我发送一个非字符串 MessageID,它可以通过 DTO。 请帮忙
【问题讨论】:
标签: javascript node.js validation apache-kafka nestjs