【发布时间】:2019-08-28 15:16:23
【问题描述】:
我尝试使用命令 DTO,但无法识别他的处理程序。
当我记录 DTO 时,它是一个没有 CreateUserCommand 签名的简单对象 {...}。
这是我的控制器:
async index(@Body() createUserCommand: CreateUserCommand): Promise<User> {
console.log(createUserCommand);
return await this.commandBus.execute(createUserCommand);
}
我得到以下输出:
{
firstName: 'xxx',
lastName: 'xxx',
email: 'xxx@xxx.com',
password: 'xxx'
}
当我尝试直接使用它正在工作的命令时:
const command = new CreateUserCommand();
command.firstName = 'xxx';
command.lastName = 'xxx';
command.email = 'xxx@xxx.com';
command.password = 'xxx';
return await this.commandBus.execute(createUserCommand);
以下输出:
CreateUserCommand {
firstName: 'xxx',
lastName: 'xxx',
email: 'xxx@xxx.com',
password: 'xxx'
}
是否可以将 DTO 用作命令处理程序?
【问题讨论】:
标签: javascript node.js typescript nestjs class-transformer