refacto et TU user

This commit is contained in:
styve Lioumba
2025-11-17 17:59:45 +01:00
parent 778cb95724
commit 9669b2b5b4
11 changed files with 377 additions and 185 deletions

View File

@@ -6,6 +6,8 @@ import { LoaderAction } from '@app/domain/loader-action.util';
import { ActionType } from '@app/domain/action-type.util';
import { ErrorResponse } from '@app/domain/error-response.util';
import { UserViewModel } from '@app/ui/users/user.presenter.model';
import { UserPresenter } from '@app/ui/users/user.presenter';
import { AuthService } from '@app/core/services/authentication/auth.service';
@Injectable({
providedIn: 'root',
@@ -13,6 +15,8 @@ import { UserViewModel } from '@app/ui/users/user.presenter.model';
export class UserFacade {
private readonly userRepository = inject(USER_REPOSITORY_TOKEN);
private readonly authService = inject(AuthService);
private readonly getUseCase = new GetUserUseCase(this.userRepository);
private readonly updateUseCase = new UpdateUserUseCase(this.userRepository);
@@ -25,11 +29,13 @@ export class UserFacade {
message: null,
});
private readonly userPresenter = new UserPresenter();
loadOne(userId: string) {
this.handleError(ActionType.READ, false, null, true);
this.getUseCase.execute(userId).subscribe({
next: (user) => {
this.user.set(user);
this.user.set(this.userPresenter.toViewModel(user));
this.handleError(ActionType.READ, false, null, false);
},
error: (err) => {
@@ -42,7 +48,8 @@ export class UserFacade {
this.handleError(ActionType.UPDATE, false, null, true);
this.updateUseCase.execute(userId, user).subscribe({
next: (user) => {
this.user.set(user);
this.user.set(this.userPresenter.toViewModel(user));
this.authService.updateUser();
this.handleError(ActionType.UPDATE, false, null, false);
},
error: (err) => {