nestjs在更新到postgress后返回空对象
我最近遇到了一个问题 当我与postgress DB交互并要求返回对象n get a blanknestjs在更新到postgress后返回空对象,nestjs,typeorm,Nestjs,Typeorm,我最近遇到了一个问题 当我与postgress DB交互并要求返回对象n get a blank{}时,我不确定它是否返回了数组中包含对象的数组 以下是我的代码供参考: public async updateUserById(patchUser: CreateUserDto, userId: number, profile_image: any) { const user = await this._userRepository.createQueryBuilder('use
{}
时,我不确定它是否返回了数组中包含对象的数组
以下是我的代码供参考:
public async updateUserById(patchUser: CreateUserDto, userId: number, profile_image: any) {
const user = await this._userRepository.createQueryBuilder('user')
.where('user.id = :id', {id: userId})
.getOne()
if(!user) {
throw new InternalServerErrorException(`User with id ${userId} does not exist`);
}
user.name = patchUser.name;
user.surname = patchUser.surname;
user.profile_image = profile_image.location;
user.email = patchUser.email;
return await this._userRepository.save(user);
}
我也尝试过:
const foundUser = await this._userRepository.save(user);
return foundUser
如果运气不好我很确定TypeORM的
save
方法说它会返回一些东西,但不一定会返回。我最终返回在TypeORM调用之前创建的对象。在你的情况下是这样的
。。。
user.name=patchUser.name;
user.name=patchUser.surmame;
...
等待此消息。\u userREpository.save(user);
返回用户;
我不知道自己做错了什么,因为我可以注销该用户,但无法返回。我在getUserById上也遇到了同样的问题。但是,我可以返回getAllUsers,并且我正在使用完全相同的方法…```public async getDriverById(driverId:number):Promise{const driver=等待此操作。_driversEntry.createQueryBuilder('driver')。其中('driver.id=:id',{id:driverId})。leftJoinAndSelect(“driver.user”,“user”).getOne()console.log(driver);返回driver;}```