website refactor
This commit is contained in:
@@ -18,6 +18,7 @@ import { GetProfileOverviewUseCase } from '@core/racing/application/use-cases/Ge
|
||||
import { GetTotalDriversUseCase } from '@core/racing/application/use-cases/GetTotalDriversUseCase';
|
||||
import { IsDriverRegisteredForRaceUseCase } from '@core/racing/application/use-cases/IsDriverRegisteredForRaceUseCase';
|
||||
import { UpdateDriverProfileUseCase, type UpdateDriverProfileInput } from '@core/racing/application/use-cases/UpdateDriverProfileUseCase';
|
||||
import { GetDriverUseCase } from '@core/racing/application/use-cases/GetDriverUseCase';
|
||||
|
||||
// Presenters
|
||||
import { CompleteOnboardingPresenter } from './presenters/CompleteOnboardingPresenter';
|
||||
@@ -29,11 +30,9 @@ import { DriverStatsPresenter } from './presenters/DriverStatsPresenter';
|
||||
import { GetDriverLiveriesPresenter } from './presenters/GetDriverLiveriesPresenter';
|
||||
|
||||
// Tokens
|
||||
import type { IDriverRepository } from '@core/racing/domain/repositories/IDriverRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import {
|
||||
COMPLETE_DRIVER_ONBOARDING_USE_CASE_TOKEN,
|
||||
DRIVER_REPOSITORY_TOKEN,
|
||||
GET_DRIVER_LIVERIES_USE_CASE_TOKEN,
|
||||
GET_DRIVERS_LEADERBOARD_USE_CASE_TOKEN,
|
||||
GET_PROFILE_OVERVIEW_USE_CASE_TOKEN,
|
||||
@@ -41,6 +40,7 @@ import {
|
||||
IS_DRIVER_REGISTERED_FOR_RACE_USE_CASE_TOKEN,
|
||||
LOGGER_TOKEN,
|
||||
UPDATE_DRIVER_PROFILE_USE_CASE_TOKEN,
|
||||
GET_DRIVER_USE_CASE_TOKEN,
|
||||
} from './DriverTokens';
|
||||
|
||||
@Injectable()
|
||||
@@ -60,8 +60,8 @@ export class DriverService {
|
||||
private readonly updateDriverProfileUseCase: UpdateDriverProfileUseCase,
|
||||
@Inject(GET_PROFILE_OVERVIEW_USE_CASE_TOKEN)
|
||||
private readonly getProfileOverviewUseCase: GetProfileOverviewUseCase,
|
||||
@Inject(DRIVER_REPOSITORY_TOKEN)
|
||||
private readonly driverRepository: IDriverRepository, // TODO must be removed from service
|
||||
@Inject(GET_DRIVER_USE_CASE_TOKEN)
|
||||
private readonly getDriverUseCase: GetDriverUseCase,
|
||||
@Inject(LOGGER_TOKEN)
|
||||
private readonly logger: Logger,
|
||||
// Injected presenters (optional for module test compatibility)
|
||||
@@ -138,8 +138,11 @@ export class DriverService {
|
||||
async getCurrentDriver(userId: string): Promise<GetDriverOutputDTO | null> {
|
||||
this.logger.debug(`[DriverService] Fetching current driver for userId: ${userId}`);
|
||||
|
||||
const driver = await this.driverRepository.findById(userId);
|
||||
await this.driverPresenter!.present(Result.ok(driver));
|
||||
const result = await this.getDriverUseCase.execute({ driverId: userId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().message);
|
||||
}
|
||||
await this.driverPresenter!.present(Result.ok(result.unwrap()));
|
||||
return this.driverPresenter!.getResponseModel();
|
||||
}
|
||||
|
||||
@@ -157,15 +160,22 @@ export class DriverService {
|
||||
await this.updateDriverProfileUseCase.execute(input);
|
||||
|
||||
// Get the updated driver and present it
|
||||
const driver = await this.driverRepository.findById(driverId);
|
||||
await this.driverPresenter!.present(Result.ok(driver));
|
||||
const result = await this.getDriverUseCase.execute({ driverId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().message);
|
||||
}
|
||||
await this.driverPresenter!.present(Result.ok(result.unwrap()));
|
||||
return this.driverPresenter!.getResponseModel();
|
||||
}
|
||||
|
||||
async getDriver(driverId: string): Promise<GetDriverOutputDTO | null> {
|
||||
this.logger.debug(`[DriverService] Fetching driver for driverId: ${driverId}`);
|
||||
|
||||
const driver = await this.driverRepository.findById(driverId);
|
||||
const result = await this.getDriverUseCase.execute({ driverId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().message);
|
||||
}
|
||||
const driver = result.unwrap();
|
||||
if (!driver) {
|
||||
return null;
|
||||
}
|
||||
@@ -193,4 +203,4 @@ export class DriverService {
|
||||
await this.getDriverLiveriesPresenter!.present(result);
|
||||
return this.getDriverLiveriesPresenter!.getResponseModel()!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user