fix presenter issues

This commit is contained in:
2025-12-27 01:39:18 +01:00
parent 9a74e16f11
commit 901fb1ac83
9 changed files with 65 additions and 55 deletions

View File

@@ -2,7 +2,7 @@ import type { IDriverRepository } from '../../domain/repositories/IDriverReposit
import { Driver } from '../../domain/entities/Driver';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCase } from '@core/shared/application';
import type { UseCase, UseCaseOutputPort } from '@core/shared/application';
import type { Logger } from '@core/shared/application/Logger';
export interface CompleteDriverOnboardingInput {
@@ -30,15 +30,16 @@ export type CompleteDriverOnboardingApplicationError = ApplicationErrorCode<
/**
* Use Case for completing driver onboarding.
*/
export class CompleteDriverOnboardingUseCase implements UseCase<CompleteDriverOnboardingInput, CompleteDriverOnboardingResult, CompleteDriverOnboardingErrorCode> {
export class CompleteDriverOnboardingUseCase implements UseCase<CompleteDriverOnboardingInput, void, CompleteDriverOnboardingErrorCode> {
constructor(
private readonly driverRepository: IDriverRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<CompleteDriverOnboardingResult>,
) {}
async execute(
input: CompleteDriverOnboardingInput,
): Promise<Result<CompleteDriverOnboardingResult, CompleteDriverOnboardingApplicationError>> {
): Promise<Result<void, CompleteDriverOnboardingApplicationError>> {
try {
const existing = await this.driverRepository.findById(input.userId);
if (existing) {
@@ -59,7 +60,8 @@ export class CompleteDriverOnboardingUseCase implements UseCase<CompleteDriverOn
await this.driverRepository.create(driver);
const result: CompleteDriverOnboardingResult = { driver };
return Result.ok(result);
this.output.present(result);
return Result.ok(void 0);
} catch (error) {
const err = error instanceof Error ? error : new Error('Unknown error');

View File

@@ -1,4 +1,4 @@
import type { Logger, UseCase } from '@core/shared/application';
import type { Logger, UseCase, 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';
@@ -42,20 +42,21 @@ export type GetDriversLeaderboardErrorCode =
* Use Case for retrieving driver leaderboard data.
* Returns a Result containing the domain leaderboard model.
*/
export class GetDriversLeaderboardUseCase implements UseCase<GetDriversLeaderboardInput, GetDriversLeaderboardResult, GetDriversLeaderboardErrorCode> {
export class GetDriversLeaderboardUseCase implements UseCase<GetDriversLeaderboardInput, void, GetDriversLeaderboardErrorCode> {
constructor(
private readonly driverRepository: IDriverRepository,
private readonly rankingService: IRankingService,
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 }>
>
> {
@@ -105,7 +106,9 @@ export class GetDriversLeaderboardUseCase implements UseCase<GetDriversLeaderboa
this.logger.debug('Successfully computed drivers leaderboard');
return Result.ok(result);
this.output.present(result);
return Result.ok(void 0);
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));

View File

@@ -1,4 +1,4 @@
import type { UseCase } from '@core/shared/application';
import type { UseCase, UseCaseOutputPort } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
@@ -17,20 +17,23 @@ export type GetTotalDriversResult = {
export type GetTotalDriversErrorCode = 'REPOSITORY_ERROR';
export class GetTotalDriversUseCase implements UseCase<GetTotalDriversInput, GetTotalDriversResult, GetTotalDriversErrorCode> {
export class GetTotalDriversUseCase implements UseCase<GetTotalDriversInput, void, GetTotalDriversErrorCode> {
constructor(
private readonly driverRepository: IDriverRepository,
private readonly output: UseCaseOutputPort<GetTotalDriversResult>,
) {}
async execute(
_input: GetTotalDriversInput,
): Promise<Result<GetTotalDriversResult, ApplicationErrorCode<GetTotalDriversErrorCode, { message: string }>>> {
): Promise<Result<void, ApplicationErrorCode<GetTotalDriversErrorCode, { message: string }>>> {
void _input;
try {
const drivers = await this.driverRepository.findAll();
const result: GetTotalDriversResult = { totalDrivers: drivers.length };
return Result.ok(result);
this.output.present(result);
return Result.ok(void 0);
} catch (error) {
const message = (error as Error | undefined)?.message ?? 'Failed to compute total drivers';

View File

@@ -1,5 +1,5 @@
import type { IRaceRegistrationRepository } from '../../domain/repositories/IRaceRegistrationRepository';
import type { Logger, UseCase } from '@core/shared/application';
import type { Logger, UseCase, UseCaseOutputPort } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
@@ -26,20 +26,22 @@ export type IsDriverRegisteredForRaceResult = {
*
* Checks if a driver is registered for a specific race.
*/
export class IsDriverRegisteredForRaceUseCase implements UseCase<IsDriverRegisteredForRaceInput, IsDriverRegisteredForRaceResult, IsDriverRegisteredForRaceErrorCode> {
export class IsDriverRegisteredForRaceUseCase implements UseCase<IsDriverRegisteredForRaceInput, void, IsDriverRegisteredForRaceErrorCode> {
constructor(
private readonly registrationRepository: IRaceRegistrationRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<IsDriverRegisteredForRaceResult>,
) {}
async execute(params: IsDriverRegisteredForRaceInput): Promise<Result<IsDriverRegisteredForRaceResult, IsDriverRegisteredForRaceApplicationError>> {
async execute(params: IsDriverRegisteredForRaceInput): Promise<Result<void, IsDriverRegisteredForRaceApplicationError>> {
this.logger.debug('IsDriverRegisteredForRaceUseCase:execute', { params });
const { raceId, driverId } = params;
try {
const isRegistered = await this.registrationRepository.isRegistered(raceId, driverId);
return Result.ok({ isRegistered, raceId, driverId });
this.output.present({ isRegistered, raceId, driverId });
return Result.ok(void 0);
} catch (error) {
this.logger.error(
'IsDriverRegisteredForRaceUseCase:execution error',