website refactor
This commit is contained in:
@@ -15,22 +15,27 @@ import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporte
|
||||
export class PenaltyService implements Service {
|
||||
private readonly apiClient: PenaltiesApiClient;
|
||||
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
this.apiClient = new PenaltiesApiClient(baseUrl, errorReporter, logger);
|
||||
constructor(apiClient?: PenaltiesApiClient) {
|
||||
if (apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
} else {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
this.apiClient = new PenaltiesApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find penalties by race ID
|
||||
*/
|
||||
async findByRaceId(raceId: string): Promise<Result<unknown[], DomainError>> {
|
||||
async findByRaceId(raceId: string): Promise<any> {
|
||||
try {
|
||||
const dto = await this.apiClient.getRacePenalties(raceId);
|
||||
return Result.ok(dto.penalties);
|
||||
const res = await this.apiClient.getRacePenalties(raceId);
|
||||
const data = (res as any).value || res;
|
||||
return data.penalties;
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to find penalties' });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +54,13 @@ export class PenaltyService implements Service {
|
||||
/**
|
||||
* Apply a penalty
|
||||
*/
|
||||
async applyPenalty(input: unknown): Promise<Result<void, DomainError>> {
|
||||
async applyPenalty(input: unknown): Promise<any> {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
await this.apiClient.applyPenalty(input as any);
|
||||
return Result.ok(undefined);
|
||||
const res = await this.apiClient.applyPenalty(input as any);
|
||||
return (res as any)?.value || res;
|
||||
} catch (error: unknown) {
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to apply penalty' });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user