refactor driver module (wip)

This commit is contained in:
2025-12-22 01:43:34 +01:00
parent b445d6dd37
commit e7dbec4a85
31 changed files with 379 additions and 395 deletions

View File

@@ -1,5 +1,5 @@
import { Result } from '@core/shared/application/Result';
import type { UseCaseOutputPort, UseCase } from '@core/shared/application';
import type { UseCase } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Logger } from '@core/shared/application/Logger';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
@@ -23,16 +23,15 @@ export type UpdateDriverProfileErrorCode =
* Encapsulates domain entity mutation. Mapping to DTOs is handled by presenters
* in the presentation layer through the output port.
*/
export class UpdateDriverProfileUseCase implements UseCase<UpdateDriverProfileInput, void, UpdateDriverProfileErrorCode> {
export class UpdateDriverProfileUseCase implements UseCase<UpdateDriverProfileInput, UpdateDriverProfileResult, UpdateDriverProfileErrorCode> {
constructor(
private readonly driverRepository: IDriverRepository,
private readonly output: UseCaseOutputPort<UpdateDriverProfileResult>,
private readonly logger: Logger,
) {}
async execute(
input: UpdateDriverProfileInput,
): Promise<Result<void, ApplicationErrorCode<UpdateDriverProfileErrorCode, { message: string }>>> {
): Promise<Result<UpdateDriverProfileResult, ApplicationErrorCode<UpdateDriverProfileErrorCode, { message: string }>>> {
const { driverId, bio, country } = input;
if ((bio !== undefined && bio.trim().length === 0) || (country !== undefined && country.trim().length === 0)) {
@@ -62,9 +61,7 @@ export class UpdateDriverProfileUseCase implements UseCase<UpdateDriverProfileIn
await this.driverRepository.update(updated);
this.output.present(updated);
return Result.ok(undefined);
return Result.ok(updated);
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to update driver profile';