refactor driver module (wip)
This commit is contained in:
@@ -1,36 +1,17 @@
|
||||
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 { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { CreateTeamResult } from '@core/racing/application/use-cases/CreateTeamUseCase';
|
||||
import type { CreateTeamOutputDTO } from '../dtos/CreateTeamOutputDTO';
|
||||
|
||||
export type CreateTeamError = ApplicationErrorCode<CreateTeamErrorCode, { message: string }>;
|
||||
|
||||
export class CreateTeamPresenter {
|
||||
export class CreateTeamPresenter implements UseCaseOutputPort<CreateTeamResult> {
|
||||
private model: CreateTeamOutputDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
present(result: CreateTeamResult): void {
|
||||
this.model = {
|
||||
id: output.team.id,
|
||||
id: result.team.id,
|
||||
success: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user