const pictureEntity = updateUserDto?.picture
? await this.filesService.find(updateUserDto.picture)
: null;
if (pictureEntity) {
const pictureEntity.url = await this.filesService.getFileUrl(pictureEntity);
}
Is this the correct way to assign the value to pictureEntity? Basically if property picture is not defined, I'm not supposed to use the service find in filesService because typeORM will return the first value that it finds if property picture is null or undefined.
I was doing this:
if (updateUserDto?.picture) {
const pictureEntity = await this.filesService.find(updateUserDto.picture);
}
but TS would complain because I'm declaring a variable inside an If.
You could do:
If
updateUserDto
isnull
orundefined
,pictureEntity
will beundefined
. Otherwise it willawait
your other promise.Edit:
There's also no need for a
const
here:You don't use
const
to create object properties.