mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04: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
eee8668317
commit
30a0b25094
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…
Add table
Add a link
Reference in a new issue