40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { DriverProfileUpdateService } from '@/lib/services/drivers/DriverProfileUpdateService';
|
|
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
|
import { Result } from '@/lib/contracts/Result';
|
|
|
|
export interface UpdateDriverProfileCommand {
|
|
bio?: string;
|
|
country?: string;
|
|
}
|
|
|
|
export type UpdateDriverProfileMutationError = 'DRIVER_PROFILE_UPDATE_FAILED';
|
|
|
|
export class UpdateDriverProfileMutation
|
|
implements Mutation<UpdateDriverProfileCommand, void, UpdateDriverProfileMutationError>
|
|
{
|
|
private readonly service: DriverProfileUpdateService;
|
|
|
|
constructor() {
|
|
this.service = new DriverProfileUpdateService();
|
|
}
|
|
|
|
async execute(
|
|
command: UpdateDriverProfileCommand,
|
|
): Promise<Result<void, UpdateDriverProfileMutationError>> {
|
|
try {
|
|
const result = await this.service.updateProfile({
|
|
bio: command.bio,
|
|
country: command.country,
|
|
});
|
|
|
|
if (result.isErr()) {
|
|
return Result.err('DRIVER_PROFILE_UPDATE_FAILED');
|
|
}
|
|
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('DRIVER_PROFILE_UPDATE_FAILED');
|
|
}
|
|
}
|
|
}
|