module cleanup

This commit is contained in:
2025-12-19 01:22:45 +01:00
parent d617654928
commit d0fac9e6c1
135 changed files with 5104 additions and 1315 deletions

View File

@@ -1,20 +1,19 @@
import { Injectable, Inject } from '@nestjs/common';
import {
AllRacesPageViewModel,
RaceStatsDto,
ImportRaceResultsInput,
ImportRaceResultsSummaryViewModel,
RaceDetailViewModelDto,
RacesPageDataViewModelDto,
RaceResultsDetailViewModelDto,
RaceWithSOFViewModelDto,
RaceProtestsViewModelDto,
RacePenaltiesViewModelDto,
GetRaceDetailParamsDto,
RegisterForRaceParamsDto,
WithdrawFromRaceParamsDto,
RaceActionParamsDto,
} from './dtos/RaceDTO';
import type { AllRacesPageViewModel } from '@core/racing/application/presenters/IGetAllRacesPresenter';
import type { GetTotalRacesViewModel } from '@core/racing/application/presenters/IGetTotalRacesPresenter';
import type { RaceDetailViewModel } from '@core/racing/application/presenters/IRaceDetailPresenter';
import type { RacesPageViewModel } from '@core/racing/application/presenters/IRacesPagePresenter';
import type { RaceResultsDetailViewModel } from '@core/racing/application/presenters/IRaceResultsDetailPresenter';
import type { RaceWithSOFViewModel } from '@core/racing/application/presenters/IRaceWithSOFPresenter';
import type { RaceProtestsViewModel } from '@core/racing/application/presenters/IRaceProtestsPresenter';
import type { RacePenaltiesViewModel } from '@core/racing/application/presenters/IRacePenaltiesPresenter';
// DTOs
import { GetRaceDetailParamsDTO } from './dtos/GetRaceDetailParamsDTO';
import { RegisterForRaceParamsDTO } from './dtos/RegisterForRaceParamsDTO';
import { WithdrawFromRaceParamsDTO } from './dtos/WithdrawFromRaceParamsDTO';
import { RaceActionParamsDTO } from './dtos/RaceActionParamsDTO';
import { ImportRaceResultsDTO } from './dtos/ImportRaceResultsDTO';
// Core imports
import type { Logger } from '@core/shared/application/Logger';
@@ -46,6 +45,13 @@ import { GetAllRacesPresenter } from './presenters/GetAllRacesPresenter';
import { GetTotalRacesPresenter } from './presenters/GetTotalRacesPresenter';
import { ImportRaceResultsApiPresenter } from './presenters/ImportRaceResultsApiPresenter';
// Command DTOs
import { FileProtestCommandDTO } from './dtos/FileProtestCommandDTO';
import { QuickPenaltyCommandDTO } from './dtos/QuickPenaltyCommandDTO';
import { ApplyPenaltyCommandDTO } from './dtos/ApplyPenaltyCommandDTO';
import { RequestProtestDefenseCommandDTO } from './dtos/RequestProtestDefenseCommandDTO';
import { ReviewProtestCommandDTO } from './dtos/ReviewProtestCommandDTO';
// Tokens
import { LOGGER_TOKEN } from './RaceProviders';
@@ -66,7 +72,6 @@ export class RaceService {
private readonly withdrawFromRaceUseCase: WithdrawFromRaceUseCase,
private readonly cancelRaceUseCase: CancelRaceUseCase,
private readonly completeRaceUseCase: CompleteRaceUseCase,
private readonly importRaceResultsUseCase: ImportRaceResultsUseCase,
private readonly fileProtestUseCase: FileProtestUseCase,
private readonly quickPenaltyUseCase: QuickPenaltyUseCase,
private readonly applyPenaltyUseCase: ApplyPenaltyUseCase,
@@ -83,34 +88,33 @@ export class RaceService {
return presenter.getViewModel()!;
}
async getTotalRaces(): Promise<RaceStatsDto> {
async getTotalRaces(): Promise<GetTotalRacesViewModel> {
this.logger.debug('[RaceService] Fetching total races count.');
const presenter = new GetTotalRacesPresenter();
await this.getTotalRacesUseCase.execute({}, presenter);
return presenter.getViewModel()!;
}
async importRaceResults(input: ImportRaceResultsInput): Promise<ImportRaceResultsSummaryViewModel> {
async importRaceResults(input: ImportRaceResultsDTO): Promise<ImportRaceResultsSummaryDTO> {
this.logger.debug('Importing race results:', input);
const presenter = new ImportRaceResultsApiPresenter();
await this.importRaceResultsApiUseCase.execute({ raceId: input.raceId, resultsFileContent: input.resultsFileContent }, presenter);
return presenter.getViewModel()!;
}
async getRaceDetail(params: GetRaceDetailParamsDto): Promise<RaceDetailViewModelDto> {
async getRaceDetail(params: GetRaceDetailParamsDTO): Promise<RaceDetailViewModel> {
this.logger.debug('[RaceService] Fetching race detail:', params);
const presenter = new RaceDetailPresenter();
const result = await this.getRaceDetailUseCase.execute(params);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to get race detail');
throw new Error('Failed to get race detail');
}
return result.value;
}
async getRacesPageData(): Promise<RacesPageDataViewModelDto> {
async getRacesPageData(): Promise<RacesPageViewModel> {
this.logger.debug('[RaceService] Fetching races page data.');
const result = await this.getRacesPageDataUseCase.execute();
@@ -122,7 +126,7 @@ export class RaceService {
return result.value;
}
async getAllRacesPageData(): Promise<RacesPageDataViewModelDto> {
async getAllRacesPageData(): Promise<RacesPageViewModel> {
this.logger.debug('[RaceService] Fetching all races page data.');
const result = await this.getAllRacesPageDataUseCase.execute();
@@ -134,165 +138,143 @@ export class RaceService {
return result.value;
}
async getRaceResultsDetail(raceId: string): Promise<RaceResultsDetailViewModelDto> {
async getRaceResultsDetail(raceId: string): Promise<RaceResultsDetailViewModel> {
this.logger.debug('[RaceService] Fetching race results detail:', { raceId });
const result = await this.getRaceResultsDetailUseCase.execute({ raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to get race results detail');
throw new Error('Failed to get race results detail');
}
return result.value;
}
async getRaceWithSOF(raceId: string): Promise<RaceWithSOFViewModelDto> {
async getRaceWithSOF(raceId: string): Promise<RaceWithSOFViewModel> {
this.logger.debug('[RaceService] Fetching race with SOF:', { raceId });
const result = await this.getRaceWithSOFUseCase.execute({ raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to get race with SOF');
throw new Error('Failed to get race with SOF');
}
return result.value;
}
async getRaceProtests(raceId: string): Promise<RaceProtestsViewModelDto> {
async getRaceProtests(raceId: string): Promise<RaceProtestsViewModel> {
this.logger.debug('[RaceService] Fetching race protests:', { raceId });
const result = await this.getRaceProtestsUseCase.execute({ raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to get race protests');
throw new Error('Failed to get race protests');
}
return result.value;
}
async getRacePenalties(raceId: string): Promise<RacePenaltiesViewModelDto> {
async getRacePenalties(raceId: string): Promise<RacePenaltiesViewModel> {
this.logger.debug('[RaceService] Fetching race penalties:', { raceId });
const result = await this.getRacePenaltiesUseCase.execute({ raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to get race penalties');
throw new Error('Failed to get race penalties');
}
return result.value;
}
async registerForRace(params: RegisterForRaceParamsDto): Promise<void> {
async registerForRace(params: RegisterForRaceParamsDTO): Promise<void> {
this.logger.debug('[RaceService] Registering for race:', params);
const result = await this.registerForRaceUseCase.execute(params);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to register for race');
throw new Error('Failed to register for race');
}
}
async withdrawFromRace(params: WithdrawFromRaceParamsDto): Promise<void> {
async withdrawFromRace(params: WithdrawFromRaceParamsDTO): Promise<void> {
this.logger.debug('[RaceService] Withdrawing from race:', params);
const result = await this.withdrawFromRaceUseCase.execute(params);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to withdraw from race');
throw new Error('Failed to withdraw from race');
}
}
async cancelRace(params: RaceActionParamsDto): Promise<void> {
async cancelRace(params: RaceActionParamsDTO): Promise<void> {
this.logger.debug('[RaceService] Cancelling race:', params);
const result = await this.cancelRaceUseCase.execute({ raceId: params.raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to cancel race');
throw new Error('Failed to cancel race');
}
}
async completeRace(params: RaceActionParamsDto): Promise<void> {
async completeRace(params: RaceActionParamsDTO): Promise<void> {
this.logger.debug('[RaceService] Completing race:', params);
const result = await this.completeRaceUseCase.execute({ raceId: params.raceId });
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to complete race');
}
}
async importRaceResultsAlt(params: { raceId: string; resultsFileContent: string }): Promise<void> {
this.logger.debug('[RaceService] Importing race results (alt):', params);
const result = await this.importRaceResultsUseCase.execute({
raceId: params.raceId,
resultsFileContent: params.resultsFileContent,
});
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to import race results');
throw new Error('Failed to complete race');
}
}
async fileProtest(command: any): Promise<any> {
async fileProtest(command: FileProtestCommandDTO): Promise<void> {
this.logger.debug('[RaceService] Filing protest:', command);
const result = await this.fileProtestUseCase.execute(command);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to file protest');
throw new Error('Failed to file protest');
}
return result.value;
}
async applyQuickPenalty(command: any): Promise<any> {
async applyQuickPenalty(command: QuickPenaltyCommandDTO): Promise<void> {
this.logger.debug('[RaceService] Applying quick penalty:', command);
const result = await this.quickPenaltyUseCase.execute(command);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to apply quick penalty');
throw new Error('Failed to apply quick penalty');
}
return result.value;
}
async applyPenalty(command: any): Promise<any> {
async applyPenalty(command: ApplyPenaltyCommandDTO): Promise<void> {
this.logger.debug('[RaceService] Applying penalty:', command);
const result = await this.applyPenaltyUseCase.execute(command);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to apply penalty');
throw new Error('Failed to apply penalty');
}
return result.value;
}
async requestProtestDefense(command: any): Promise<any> {
async requestProtestDefense(command: RequestProtestDefenseCommandDTO): Promise<void> {
this.logger.debug('[RaceService] Requesting protest defense:', command);
const result = await this.requestProtestDefenseUseCase.execute(command);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to request protest defense');
throw new Error('Failed to request protest defense');
}
return result.value;
}
async reviewProtest(command: any): Promise<any> {
async reviewProtest(command: ReviewProtestCommandDTO): Promise<void> {
this.logger.debug('[RaceService] Reviewing protest:', command);
const result = await this.reviewProtestUseCase.execute(command);
if (result.isErr()) {
throw new Error(result.error.details.message || 'Failed to review protest');
throw new Error('Failed to review protest');
}
return result.value;
}
}