website refactor
This commit is contained in:
20
core/racing/application/use-cases/GetDriverUseCase.ts
Normal file
20
core/racing/application/use-cases/GetDriverUseCase.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { Driver } from '../../domain/entities/Driver';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
|
||||
export type GetDriverInput = {
|
||||
driverId: string;
|
||||
};
|
||||
|
||||
export class GetDriverUseCase {
|
||||
constructor(private readonly driverRepository: IDriverRepository) {}
|
||||
|
||||
async execute(input: GetDriverInput): Promise<Result<Driver | null>> {
|
||||
try {
|
||||
const driver = await this.driverRepository.findById(input.driverId);
|
||||
return Result.ok(driver);
|
||||
} catch (error) {
|
||||
return Result.err(error instanceof Error ? error : new Error(String(error)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user