2025-09-05 17:49:48 +02:00
|
|
|
/**
|
|
|
|
|
* Onboarding Service - Mirror backend onboarding endpoints
|
|
|
|
|
*/
|
|
|
|
|
import { apiClient } from '../client';
|
|
|
|
|
import { UserProgress, UpdateStepRequest } from '../types/onboarding';
|
|
|
|
|
|
|
|
|
|
export class OnboardingService {
|
2025-09-06 19:40:47 +02:00
|
|
|
private readonly baseUrl = '/users/me/onboarding';
|
2025-09-05 17:49:48 +02:00
|
|
|
|
|
|
|
|
async getUserProgress(userId: string): Promise<UserProgress> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// Backend uses current user from auth token, so userId parameter is ignored
|
|
|
|
|
return apiClient.get<UserProgress>(`${this.baseUrl}/progress`);
|
2025-09-05 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateStep(userId: string, stepData: UpdateStepRequest): Promise<UserProgress> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// Backend uses current user from auth token, so userId parameter is ignored
|
|
|
|
|
return apiClient.put<UserProgress>(`${this.baseUrl}/step`, stepData);
|
2025-09-05 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async markStepCompleted(
|
|
|
|
|
userId: string,
|
|
|
|
|
stepName: string,
|
|
|
|
|
data?: Record<string, any>
|
|
|
|
|
): Promise<UserProgress> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// Backend uses current user from auth token, so userId parameter is ignored
|
|
|
|
|
// Backend expects UpdateStepRequest format for completion
|
|
|
|
|
return apiClient.put<UserProgress>(`${this.baseUrl}/step`, {
|
2025-09-05 17:49:48 +02:00
|
|
|
step_name: stepName,
|
2025-09-06 19:40:47 +02:00
|
|
|
completed: true,
|
2025-09-05 17:49:48 +02:00
|
|
|
data: data,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async resetProgress(userId: string): Promise<UserProgress> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// Note: Backend doesn't have a reset endpoint, this might need to be implemented
|
|
|
|
|
// For now, we'll throw an error
|
|
|
|
|
throw new Error('Reset progress functionality not implemented in backend');
|
2025-09-05 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getStepDetails(stepName: string): Promise<{
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
dependencies: string[];
|
|
|
|
|
estimated_time_minutes: number;
|
|
|
|
|
}> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// This endpoint doesn't exist in backend, we'll need to implement it or mock it
|
|
|
|
|
throw new Error('getStepDetails functionality not implemented in backend');
|
2025-09-05 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAllSteps(): Promise<Array<{
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
dependencies: string[];
|
|
|
|
|
estimated_time_minutes: number;
|
|
|
|
|
}>> {
|
2025-09-06 19:40:47 +02:00
|
|
|
// This endpoint doesn't exist in backend, we'll need to implement it or mock it
|
|
|
|
|
throw new Error('getAllSteps functionality not implemented in backend');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getNextStep(): Promise<{ step: string; completed?: boolean }> {
|
|
|
|
|
// This endpoint exists in backend
|
|
|
|
|
return apiClient.get(`${this.baseUrl}/next-step`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async canAccessStep(stepName: string): Promise<{ can_access: boolean; reason?: string }> {
|
|
|
|
|
// This endpoint exists in backend
|
|
|
|
|
return apiClient.get(`${this.baseUrl}/can-access/${stepName}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async completeOnboarding(): Promise<{ success: boolean; message: string }> {
|
|
|
|
|
// This endpoint exists in backend
|
|
|
|
|
return apiClient.post(`${this.baseUrl}/complete`);
|
2025-09-05 17:49:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const onboardingService = new OnboardingService();
|