50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { RacesApiClient } from '../../api/races/RacesApiClient';
|
|
import { RaceResultsDetailViewModel } from '../../view-models/RaceResultsDetailViewModel';
|
|
import { RaceWithSOFViewModel } from '../../view-models/RaceWithSOFViewModel';
|
|
import { ImportRaceResultsSummaryViewModel } from '../../view-models/ImportRaceResultsSummaryViewModel';
|
|
|
|
// TODO: Move this type to apps/website/lib/types/generated when available
|
|
type ImportRaceResultsInputDto = { raceId: string; results: Array<unknown> };
|
|
|
|
// TODO: Move this type to apps/website/lib/types/generated when available
|
|
type ImportRaceResultsSummaryDto = {
|
|
raceId: string;
|
|
importedCount: number;
|
|
errors: string[];
|
|
};
|
|
|
|
/**
|
|
* Race Results Service
|
|
*
|
|
* Orchestrates race results operations including viewing, importing, and SOF calculations.
|
|
* All dependencies are injected via constructor.
|
|
*/
|
|
export class RaceResultsService {
|
|
constructor(
|
|
private readonly apiClient: RacesApiClient
|
|
) {}
|
|
|
|
/**
|
|
* Get race results detail with view model transformation
|
|
*/
|
|
async getResultsDetail(raceId: string, currentUserId?: string): Promise<RaceResultsDetailViewModel> {
|
|
const dto = await this.apiClient.getResultsDetail(raceId);
|
|
return new RaceResultsDetailViewModel(dto, currentUserId || '');
|
|
}
|
|
|
|
/**
|
|
* Get race with strength of field calculation
|
|
*/
|
|
async getWithSOF(raceId: string): Promise<RaceWithSOFViewModel> {
|
|
const dto = await this.apiClient.getWithSOF(raceId);
|
|
return new RaceWithSOFViewModel(dto);
|
|
}
|
|
|
|
/**
|
|
* Import race results and get summary
|
|
*/
|
|
async importResults(raceId: string, input: ImportRaceResultsInputDto): Promise<ImportRaceResultsSummaryViewModel> {
|
|
const dto = await this.apiClient.importResults(raceId, input) as ImportRaceResultsSummaryDto;
|
|
return new ImportRaceResultsSummaryViewModel(dto);
|
|
}
|
|
} |