refactor core presenters
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { TotalDriversResultDTO } from '../presenters/ITotalDriversPresenter';
|
||||
import type { TotalDriversOutputPort } from '../ports/output/TotalDriversOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
@@ -8,21 +8,21 @@ import type { Logger } from '@core/shared/application';
|
||||
/**
|
||||
* Use Case for retrieving total number of drivers.
|
||||
*/
|
||||
export class GetTotalDriversUseCase implements AsyncUseCase<void, TotalDriversResultDTO, 'REPOSITORY_ERROR'>
|
||||
export class GetTotalDriversUseCase implements AsyncUseCase<void, TotalDriversOutputPort, 'REPOSITORY_ERROR'>
|
||||
{
|
||||
constructor(
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<Result<TotalDriversResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
async execute(): Promise<Result<TotalDriversOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
try {
|
||||
const drivers = await this.driverRepository.findAll();
|
||||
const dto: TotalDriversResultDTO = {
|
||||
const output: TotalDriversOutputPort = {
|
||||
totalDrivers: drivers.length,
|
||||
};
|
||||
|
||||
return Result.ok(dto);
|
||||
return Result.ok(output);
|
||||
} catch (error) {
|
||||
this.logger.error('Error retrieving total drivers', error as Error);
|
||||
return Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'Failed to retrieve total drivers' } });
|
||||
|
||||
Reference in New Issue
Block a user