fix : #27 gestion des typo

This commit is contained in:
styve Lioumba
2025-12-03 15:48:10 +01:00
parent 0c768296d1
commit 45b4dd1dad
7 changed files with 30 additions and 19 deletions

View File

@@ -6,4 +6,7 @@ export interface UserViewModel {
email: string;
name: string;
avatar: string;
firstName?: string;
lastName?: string;
slug?: string;
}

View File

@@ -3,7 +3,11 @@ import { User } from '@app/domain/users/user.model';
export class UserPresenter {
toViewModel(user: User): UserViewModel {
return {
const slug = user.name
? user.name.toLowerCase().replace(/\s/g, '-')
: user.email.split('@')[0].toLowerCase().trim();
let userViewModel: UserViewModel = {
id: user.id,
username: user.username,
verified: user.verified,
@@ -11,7 +15,16 @@ export class UserPresenter {
email: user.email,
name: user.name,
avatar: user.avatar,
slug,
};
if (user.name) {
const firstName = user.name.split(' ').slice(0, -1).join(' ').toLowerCase().trim() ?? '';
const lastName = user.name.split(' ').slice(-1)[0].toUpperCase().trim() ?? '';
userViewModel = { ...userViewModel, firstName, lastName };
}
return userViewModel;
}
toViewModels(users: User[]): UserViewModel[] {