21 lines
672 B
TypeScript
21 lines
672 B
TypeScript
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)));
|
|
}
|
|
}
|
|
}
|