refactor
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import { Driver } from '../../domain/entities/Driver';
|
||||
import { Result } from '@core/shared/result/Result';
|
||||
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { CompleteDriverOnboardingCommand } from './CompleteDriverOnboardingCommand';
|
||||
|
||||
/**
|
||||
* Use Case for completing driver onboarding.
|
||||
*/
|
||||
export class CompleteDriverOnboardingUseCase
|
||||
implements AsyncUseCase<CompleteDriverOnboardingCommand, Result<{ driverId: string }, RacingDomainValidationError>>
|
||||
implements AsyncUseCase<CompleteDriverOnboardingCommand, { driverId: string }, string>
|
||||
{
|
||||
constructor(private readonly driverRepository: IDriverRepository) {}
|
||||
|
||||
async execute(command: CompleteDriverOnboardingCommand): Promise<Result<{ driverId: string }, RacingDomainValidationError>> {
|
||||
async execute(command: CompleteDriverOnboardingCommand): Promise<Result<{ driverId: string }, ApplicationErrorCode<string>>> {
|
||||
try {
|
||||
// Check if driver already exists
|
||||
const existing = await this.driverRepository.findById(command.userId);
|
||||
if (existing) {
|
||||
return Result.err(new RacingDomainValidationError('Driver already exists'));
|
||||
return Result.err({ code: 'DRIVER_ALREADY_EXISTS' });
|
||||
}
|
||||
|
||||
// Create new driver
|
||||
@@ -33,8 +33,8 @@ export class CompleteDriverOnboardingUseCase
|
||||
await this.driverRepository.create(driver);
|
||||
|
||||
return Result.ok({ driverId: driver.id });
|
||||
} catch (error) {
|
||||
return Result.err(new RacingDomainValidationError(error instanceof Error ? error.message : 'Unknown error'));
|
||||
} catch {
|
||||
return Result.err({ code: 'UNKNOWN_ERROR' });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user