53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { OnboardingService } from '@/lib/services/onboarding/OnboardingService';
|
|
import type { Mutation } from '@/lib/contracts/mutations/Mutation';
|
|
|
|
export interface CompleteOnboardingCommand {
|
|
firstName: string;
|
|
lastName: string;
|
|
displayName: string;
|
|
country: string;
|
|
timezone?: string;
|
|
bio?: string;
|
|
}
|
|
|
|
export type CompleteOnboardingMutationError = 'onboardingFailed';
|
|
|
|
export class CompleteOnboardingMutation
|
|
implements
|
|
Mutation<
|
|
CompleteOnboardingCommand,
|
|
void,
|
|
CompleteOnboardingMutationError
|
|
>
|
|
{
|
|
private readonly service: OnboardingService;
|
|
|
|
constructor() {
|
|
this.service = new OnboardingService();
|
|
}
|
|
|
|
async execute(
|
|
command: CompleteOnboardingCommand,
|
|
): Promise<Result<void, CompleteOnboardingMutationError>> {
|
|
try {
|
|
const result = await this.service.completeOnboarding({
|
|
firstName: command.firstName,
|
|
lastName: command.lastName,
|
|
displayName: command.displayName,
|
|
country: command.country,
|
|
timezone: command.timezone,
|
|
bio: command.bio,
|
|
});
|
|
|
|
if (result.isErr()) {
|
|
return Result.err('onboardingFailed');
|
|
}
|
|
|
|
return Result.ok(undefined);
|
|
} catch (error) {
|
|
return Result.err('onboardingFailed');
|
|
}
|
|
}
|
|
}
|