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,36 +1,49 @@
import type { CreateTeamOutputPort } from '@core/racing/application/ports/output/CreateTeamOutputPort';
import type { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { CreateTeamErrorCode, CreateTeamResult } from '@core/racing/application/use-cases/CreateTeamUseCase';
import type { CreateTeamOutputDTO } from '../dtos/CreateTeamOutputDTO';
export type CreateTeamError = ApplicationErrorCode<CreateTeamErrorCode, { message: string }>;
export class CreateTeamPresenter {
private result: CreateTeamOutputDTO | null = null;
private model: CreateTeamOutputDTO | null = null;
reset(): void {
this.result = null;
this.model = null;
}
presentSuccess(output: CreateTeamOutputPort): void {
this.result = {
present(result: Result<CreateTeamResult, CreateTeamError>): void {
if (result.isErr()) {
const error = result.unwrapErr();
// Validation and expected domain errors map to an unsuccessful DTO
if (error.code === 'VALIDATION_ERROR' || error.code === 'LEAGUE_NOT_FOUND') {
this.model = {
id: '',
success: false,
};
return;
}
throw new Error(error.details?.message ?? 'Failed to create team');
}
const output = result.unwrap();
this.model = {
id: output.team.id,
success: true,
};
}
presentError(): void {
this.result = {
id: '',
success: false,
};
getResponseModel(): CreateTeamOutputDTO | null {
return this.model;
}
getViewModel(): CreateTeamOutputDTO | null {
return this.result;
}
get viewModel(): CreateTeamOutputDTO {
if (!this.result) {
get responseModel(): CreateTeamOutputDTO {
if (!this.model) {
throw new Error('Presenter not presented');
}
return this.result;
return this.model;
}
}