This commit is contained in:
2025-12-21 22:35:38 +01:00
parent 3c64f328e2
commit 9bd2e630e6
38 changed files with 736 additions and 684 deletions

View File

@@ -58,8 +58,8 @@ describe('GetAllRacesUseCase', () => {
mockRaceRepo,
mockLeagueRepo,
mockLogger,
output,
);
useCase.setOutput(output);
const race1 = {
id: 'race1',
@@ -100,8 +100,8 @@ describe('GetAllRacesUseCase', () => {
mockRaceRepo,
mockLeagueRepo,
mockLogger,
output,
);
useCase.setOutput(output);
mockRaceFindAll.mockResolvedValue([]);
mockLeagueFindAll.mockResolvedValue([]);

View File

@@ -18,13 +18,18 @@ export interface GetAllRacesResult {
export type GetAllRacesErrorCode = 'REPOSITORY_ERROR';
export class GetAllRacesUseCase {
private output: UseCaseOutputPort<GetAllRacesResult> | null = null;
constructor(
private readonly raceRepository: IRaceRepository,
private readonly leagueRepository: ILeagueRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<GetAllRacesResult>,
) {}
setOutput(output: UseCaseOutputPort<GetAllRacesResult>) {
this.output = output;
}
async execute(
_input: GetAllRacesInput,
): Promise<Result<void, ApplicationErrorCode<GetAllRacesErrorCode, { message: string }>>> {
@@ -40,6 +45,9 @@ export class GetAllRacesUseCase {
};
this.logger.debug('Successfully retrieved all races.');
if (!this.output) {
throw new Error('Output not set');
}
this.output.present(result);
return Result.ok(undefined);
} catch (error) {

View File

@@ -1,4 +1,4 @@
import type { Logger } from '@core/shared/application';
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Driver } from '../../domain/entities/Driver';
@@ -49,13 +49,14 @@ export class GetDriversLeaderboardUseCase {
private readonly driverStatsService: IDriverStatsService,
private readonly getDriverAvatar: (driverId: string) => Promise<string | undefined>,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<GetDriversLeaderboardResult>,
) {}
async execute(
input: GetDriversLeaderboardInput,
): Promise<
Result<
GetDriversLeaderboardResult,
void,
ApplicationErrorCode<GetDriversLeaderboardErrorCode, { message: string }>
>
> {
@@ -107,7 +108,9 @@ export class GetDriversLeaderboardUseCase {
this.logger.debug('Successfully computed drivers leaderboard');
return Result.ok(result);
this.output.present(result);
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));

View File

@@ -11,9 +11,7 @@ export type UpdateDriverProfileInput = {
country?: string;
};
export type UpdateDriverProfileResult = {
driverId: string;
};
export type UpdateDriverProfileResult = Driver;
export type UpdateDriverProfileErrorCode =
| 'DRIVER_NOT_FOUND'
@@ -64,11 +62,7 @@ export class UpdateDriverProfileUseCase implements UseCase<UpdateDriverProfileIn
await this.driverRepository.update(updated);
const result: UpdateDriverProfileResult = {
driverId: updated.id,
};
this.output.present(result);
this.output.present(updated);
return Result.ok(undefined);
} catch (error) {