mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 02:36:31 -05:00
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:
parent
f937042439
commit
e1e0e45434
1 changed files with 23 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { UserInfoDto } from './user-info.dto';
|
import { UserInfoDto } from './user-info.dto';
|
||||||
|
import { User } from './user.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
@ -15,4 +16,26 @@ export class UsersService {
|
||||||
photo: '',
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue