35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
|
import type { DriverDTO } from '../dto/DriverDTO';
|
|
import { EntityMappers } from '../mappers/EntityMappers';
|
|
|
|
export interface UpdateDriverProfileInput {
|
|
driverId: string;
|
|
bio?: string;
|
|
country?: string;
|
|
}
|
|
|
|
/**
|
|
* Application use case responsible for updating basic driver profile details.
|
|
* Encapsulates domain entity mutation and mapping to a DriverDTO.
|
|
*/
|
|
export class UpdateDriverProfileUseCase {
|
|
constructor(private readonly driverRepository: IDriverRepository) {}
|
|
|
|
async execute(input: UpdateDriverProfileInput): Promise<DriverDTO | null> {
|
|
const { driverId, bio, country } = input;
|
|
|
|
const existing = await this.driverRepository.findById(driverId);
|
|
if (!existing) {
|
|
return null;
|
|
}
|
|
|
|
const updated = existing.update({
|
|
...(bio !== undefined ? { bio } : {}),
|
|
...(country !== undefined ? { country } : {}),
|
|
});
|
|
|
|
const persisted = await this.driverRepository.update(updated);
|
|
const dto = EntityMappers.toDriverDTO(persisted);
|
|
return dto ?? null;
|
|
}
|
|
} |