refactor
This commit is contained in:
@@ -1,36 +1,19 @@
|
||||
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 { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { UpdateAvatarResult } from '@core/media/application/use-cases/UpdateAvatarUseCase';
|
||||
import type { UpdateAvatarOutputDTO } from '../dtos/UpdateAvatarOutputDTO';
|
||||
|
||||
type UpdateAvatarResponseModel = UpdateAvatarOutputDTO;
|
||||
|
||||
export type UpdateAvatarApplicationError = ApplicationErrorCode<
|
||||
UpdateAvatarErrorCode,
|
||||
{ message: string }
|
||||
>;
|
||||
|
||||
export class UpdateAvatarPresenter {
|
||||
export class UpdateAvatarPresenter implements UseCaseOutputPort<UpdateAvatarResult> {
|
||||
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();
|
||||
|
||||
present(result: UpdateAvatarResult): void {
|
||||
this.model = {
|
||||
success: true,
|
||||
error: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user