refactor
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { DriverDTO } from '../dto/DriverDTO';
|
||||
import { EntityMappers } from '../mappers/EntityMappers';
|
||||
@@ -15,12 +17,12 @@ export interface UpdateDriverProfileInput {
|
||||
export class UpdateDriverProfileUseCase {
|
||||
constructor(private readonly driverRepository: IDriverRepository) {}
|
||||
|
||||
async execute(input: UpdateDriverProfileInput): Promise<DriverDTO | null> {
|
||||
async execute(input: UpdateDriverProfileInput): Promise<Result<DriverDTO, ApplicationErrorCode<'DRIVER_NOT_FOUND'>>> {
|
||||
const { driverId, bio, country } = input;
|
||||
|
||||
const existing = await this.driverRepository.findById(driverId);
|
||||
if (!existing) {
|
||||
return null;
|
||||
return Result.err({ code: 'DRIVER_NOT_FOUND' });
|
||||
}
|
||||
|
||||
const updated = existing.update({
|
||||
@@ -30,6 +32,6 @@ export class UpdateDriverProfileUseCase {
|
||||
|
||||
const persisted = await this.driverRepository.update(updated);
|
||||
const dto = EntityMappers.toDriverDTO(persisted);
|
||||
return dto ?? null;
|
||||
return Result.ok(dto!);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user