34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { Result } from '@core/shared/domain/Result';
|
|
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
|
import type { DriverRepository } from '../../domain/repositories/DriverRepository';
|
|
|
|
export interface GetTotalDriversInput {}
|
|
|
|
export type GetTotalDriversErrorCode = 'REPOSITORY_ERROR';
|
|
|
|
export interface GetTotalDriversResult {
|
|
totalDrivers: number;
|
|
}
|
|
|
|
export class GetTotalDriversUseCase {
|
|
constructor(private readonly driverRepository: DriverRepository) {}
|
|
|
|
async execute(
|
|
_input: GetTotalDriversInput,
|
|
): Promise<Result<GetTotalDriversResult, ApplicationErrorCode<GetTotalDriversErrorCode, { message: string }>>> {
|
|
void _input;
|
|
try {
|
|
const drivers = await this.driverRepository.findAll();
|
|
const totalDrivers = drivers.length;
|
|
|
|
return Result.ok({ totalDrivers });
|
|
} catch (error: unknown) {
|
|
const message = error instanceof Error ? error.message : 'Failed to get total drivers';
|
|
|
|
return Result.err({
|
|
code: 'REPOSITORY_ERROR',
|
|
details: { message },
|
|
});
|
|
}
|
|
}
|
|
} |