const pictureEntity = updateUserDto?.picture
? await this.filesService.find(updateUserDto.picture)
: null;
if (pictureEntity) {
const pictureEntity.url = await this.filesService.getFileUrl(pictureEntity);
}
这是将值分配给图片实体的正确方法吗?基本上,如果未定义属性图片,我不应该使用 filesService 中的服务查找,因为如果属性图片为空或未定义,typeORM 将返回它找到的第一个值。
我正在这样做:
if (updateUserDto?.picture) {
const pictureEntity = await this.filesService.find(updateUserDto.picture);
}
但是 TS 会抱怨,因为我在 If 中声明了一个变量。