website refactor
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
||||
import type { DomainError } from '@/lib/contracts/services/Service';
|
||||
import { DriverProfileUpdateService } from '@/lib/services/drivers/DriverProfileUpdateService';
|
||||
|
||||
export interface UpdateDriverProfileCommand {
|
||||
bio?: string;
|
||||
country?: string;
|
||||
}
|
||||
|
||||
type UpdateDriverProfileMutationError = 'DRIVER_PROFILE_UPDATE_FAILED';
|
||||
|
||||
const mapToMutationError = (_error: DomainError): UpdateDriverProfileMutationError => {
|
||||
return 'DRIVER_PROFILE_UPDATE_FAILED';
|
||||
};
|
||||
|
||||
export class UpdateDriverProfileMutation
|
||||
implements Mutation<UpdateDriverProfileCommand, void, UpdateDriverProfileMutationError>
|
||||
{
|
||||
async execute(
|
||||
command: UpdateDriverProfileCommand,
|
||||
): Promise<Result<void, UpdateDriverProfileMutationError>> {
|
||||
const service = new DriverProfileUpdateService();
|
||||
const result = await service.updateProfile({ bio: command.bio, country: command.country });
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err(mapToMutationError(result.getError()));
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user