refactor driver module (wip)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { UseCase } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort, UseCase } from '@core/shared/application';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
|
||||
/**
|
||||
* Input type for retrieving total number of drivers.
|
||||
@@ -17,22 +17,19 @@ export type GetTotalDriversResult = {
|
||||
|
||||
export type GetTotalDriversErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetTotalDriversUseCase implements UseCase<GetTotalDriversInput, void, GetTotalDriversErrorCode> {
|
||||
export class GetTotalDriversUseCase implements UseCase<GetTotalDriversInput, GetTotalDriversResult, GetTotalDriversErrorCode> {
|
||||
constructor(
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly output: UseCaseOutputPort<GetTotalDriversResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
_input: GetTotalDriversInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<GetTotalDriversErrorCode, { message: string }>>> {
|
||||
): Promise<Result<GetTotalDriversResult, ApplicationErrorCode<GetTotalDriversErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const drivers = await this.driverRepository.findAll();
|
||||
const result: GetTotalDriversResult = { totalDrivers: drivers.length };
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
const message = (error as Error | undefined)?.message ?? 'Failed to compute total drivers';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user