This commit is contained in:
2025-12-21 19:53:22 +01:00
parent f2d8a23583
commit 3c64f328e2
105 changed files with 3191 additions and 1706 deletions

View File

@@ -1,21 +1,45 @@
import type { IUpdateAvatarPresenter, UpdateAvatarResult } from '@core/media/application/presenters/IUpdateAvatarPresenter';
import type { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type {
UpdateAvatarResult,
UpdateAvatarErrorCode,
} from '@core/media/application/use-cases/UpdateAvatarUseCase';
import type { UpdateAvatarOutputDTO } from '../dtos/UpdateAvatarOutputDTO';
type UpdateAvatarOutput = UpdateAvatarOutputDTO;
export class UpdateAvatarPresenter implements IUpdateAvatarPresenter {
private result: UpdateAvatarResult | null = null;
present(result: UpdateAvatarResult) {
this.result = result;
}
get viewModel(): UpdateAvatarOutput {
if (!this.result) throw new Error('Presenter not presented');
type UpdateAvatarResponseModel = UpdateAvatarOutputDTO;
return {
success: this.result.success,
error: this.result.errorMessage,
export type UpdateAvatarApplicationError = ApplicationErrorCode<
UpdateAvatarErrorCode,
{ message: string }
>;
export class UpdateAvatarPresenter {
private model: UpdateAvatarResponseModel | null = null;
reset(): void {
this.model = null;
}
present(result: Result<UpdateAvatarResult, UpdateAvatarApplicationError>): void {
if (result.isErr()) {
const error = result.unwrapErr();
throw new Error(error.details?.message ?? 'Failed to update avatar');
}
const output = result.unwrap();
this.model = {
success: true,
error: undefined,
};
}
getResponseModel(): UpdateAvatarResponseModel | null {
return this.model;
}
get responseModel(): UpdateAvatarResponseModel {
if (!this.model) throw new Error('Presenter not presented');
return this.model;
}
}