UsersService: Add toUserDto() converter

This conversion function makes sure that a photo URL exists.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-09-19 17:33:29 +02:00
parent f937042439
commit e1e0e45434
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -1,5 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { UserInfoDto } from './user-info.dto';
import { User } from './user.entity';
@Injectable()
export class UsersService {
@ -15,4 +16,26 @@ export class UsersService {
photo: '',
};
}
getPhotoUrl(user: User) {
if (user.photo) {
return user.photo;
} else {
// TODO: Create new photo, see old code
return '';
}
}
toUserDto(user: User): UserInfoDto {
if (user === undefined) {
this.logger.warn('toUserDto recieved undefined argument!');
return null;
}
return {
userName: user.userName,
displayName: user.displayName,
photo: this.getPhotoUrl(user),
email: user.email,
};
}
}