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

@@ -1,4 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { Result } from '@core/shared/application/Result';
import { CompleteOnboardingInputDTO } from './dtos/CompleteOnboardingInputDTO';
import { CompleteOnboardingOutputDTO } from './dtos/CompleteOnboardingOutputDTO';
import { DriverRegistrationStatusDTO } from './dtos/DriverRegistrationStatusDTO';
@@ -69,14 +70,20 @@ export class DriverService {
async getDriversLeaderboard(): Promise<DriversLeaderboardDTO> {
this.logger.debug('[DriverService] Fetching drivers leaderboard.');
await this.getDriversLeaderboardUseCase.execute({});
const result = await this.getDriversLeaderboardUseCase.execute({});
if (result.isErr()) {
throw new Error(result.unwrapErr().details.message);
}
return this.driversLeaderboardPresenter.getResponseModel();
}
async getTotalDrivers(): Promise<DriverStatsDTO> {
this.logger.debug('[DriverService] Fetching total drivers count.');
await this.getTotalDriversUseCase.execute({});
const result = await this.getTotalDriversUseCase.execute({});
if (result.isErr()) {
throw new Error(result.unwrapErr().details.message);
}
return this.driverStatsPresenter.getResponseModel();
}
@@ -86,7 +93,7 @@ export class DriverService {
): Promise<CompleteOnboardingOutputDTO> {
this.logger.debug('Completing onboarding for user:', userId);
await this.completeDriverOnboardingUseCase.execute({
const result = await this.completeDriverOnboardingUseCase.execute({
userId,
firstName: input.firstName,
lastName: input.lastName,
@@ -95,6 +102,9 @@ export class DriverService {
...(input.bio !== undefined ? { bio: input.bio } : {}),
});
if (result.isErr()) {
throw new Error(result.unwrapErr().details.message);
}
return this.completeOnboardingPresenter.getResponseModel();
}
@@ -103,18 +113,22 @@ export class DriverService {
): Promise<DriverRegistrationStatusDTO> {
this.logger.debug('Checking driver registration status:', query);
await this.isDriverRegisteredForRaceUseCase.execute({
const result = await this.isDriverRegisteredForRaceUseCase.execute({
raceId: query.raceId,
driverId: query.driverId,
});
if (result.isErr()) {
throw new Error(result.unwrapErr().details.message);
}
return this.driverRegistrationStatusPresenter.getResponseModel();
}
async getCurrentDriver(userId: string): Promise<GetDriverOutputDTO | null> {
this.logger.debug(`[DriverService] Fetching current driver for userId: ${userId}`);
await this.driverRepository.findById(userId);
const driver = await this.driverRepository.findById(userId);
this.driverPresenter.present(Result.ok(driver));
return this.driverPresenter.getResponseModel();
}
@@ -136,14 +150,18 @@ export class DriverService {
async getDriver(driverId: string): Promise<GetDriverOutputDTO | null> {
this.logger.debug(`[DriverService] Fetching driver for driverId: ${driverId}`);
await this.driverRepository.findById(driverId);
const driver = await this.driverRepository.findById(driverId);
this.driverPresenter.present(Result.ok(driver));
return this.driverPresenter.getResponseModel();
}
async getDriverProfile(driverId: string): Promise<GetDriverProfileOutputDTO> {
this.logger.debug(`[DriverService] Fetching driver profile for driverId: ${driverId}`);
await this.getProfileOverviewUseCase.execute({ driverId });
const result = await this.getProfileOverviewUseCase.execute({ driverId });
if (result.isErr()) {
throw new Error(result.unwrapErr().details.message);
}
return this.driverProfilePresenter.getResponseModel();
}
}