1、控制层的代码
@Post()
@Transaction()
async create(
@Body() data: Extract<CreateUserDto, CreateUserExtendDto>,
@TransactionManager() manager: EntityManager,
return this.userService.create(data, manager);
2、在服务层中
async create(
data: Extract<CreateUserDto, CreateUserExtendDto>,
manager: EntityManager,
const { name, password, email, mobile, gender, qq, address } = data;
const user: { [propName: string]: any } = await manager.save(UserEntity, {
name,
password,
email,
mobile,
gender,
});
Logger.log(JSON.stringify(user), '当前用户');
await manager.save(UserExtendEntity, {
userId: user.id,
address,
});
return '创建成功';