Fix new services implementation 1

This commit is contained in:
Urtzi Alfaro
2025-08-13 21:41:00 +02:00
parent 16b8a9d50c
commit 262b3dc9c4
13 changed files with 1702 additions and 1210 deletions

View File

@@ -56,6 +56,28 @@ export interface BusinessModelAnalysis {
recommendations: string[];
}
// Step 1: File validation result
export interface FileValidationResult {
is_valid: boolean;
total_records: number;
unique_products: number;
product_list: string[];
validation_errors: any[];
validation_warnings: any[];
summary: Record<string, any>;
}
// Step 2: AI suggestions result
export interface ProductSuggestionsResult {
suggestions: InventorySuggestion[];
business_model_analysis: BusinessModelAnalysis;
total_products: number;
high_confidence_count: number;
low_confidence_count: number;
processing_time_seconds: number;
}
// Legacy support - will be deprecated
export interface OnboardingAnalysisResult {
total_products_found: number;
inventory_suggestions: InventorySuggestion[];
@@ -143,16 +165,16 @@ export class OnboardingService {
return apiClient.get(`${this.baseEndpoint}/can-access/${stepName}`);
}
// ========== AUTOMATED INVENTORY CREATION METHODS ==========
// ========== NEW 4-STEP AUTOMATED INVENTORY CREATION METHODS ==========
/**
* Phase 1: Analyze sales data and get AI suggestions
* Step 1: Validate file and extract unique products
*/
async analyzeSalesDataForOnboarding(tenantId: string, file: File): Promise<OnboardingAnalysisResult> {
async validateFileAndExtractProducts(tenantId: string, file: File): Promise<FileValidationResult> {
const formData = new FormData();
formData.append('file', file);
return apiClient.post(`/tenants/${tenantId}/onboarding/analyze`, formData, {
return apiClient.post(`/tenants/${tenantId}/onboarding/validate-file`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
@@ -160,7 +182,26 @@ export class OnboardingService {
}
/**
* Phase 2: Create inventory from approved suggestions
* Step 2: Generate AI-powered inventory suggestions
*/
async generateInventorySuggestions(
tenantId: string,
file: File,
productList: string[]
): Promise<ProductSuggestionsResult> {
const formData = new FormData();
formData.append('file', file);
formData.append('product_list', JSON.stringify(productList));
return apiClient.post(`/tenants/${tenantId}/onboarding/generate-suggestions`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
}
/**
* Step 3: Create inventory from approved suggestions
*/
async createInventoryFromSuggestions(
tenantId: string,
@@ -176,7 +217,7 @@ export class OnboardingService {
}
/**
* Phase 3: Import sales data with inventory mapping
* Step 4: Final sales data import with inventory mapping
*/
async importSalesWithInventory(
tenantId: string,
@@ -194,6 +235,35 @@ export class OnboardingService {
});
}
// ========== LEGACY METHODS (for backward compatibility) ==========
/**
* @deprecated Use the new 4-step flow instead
* Phase 1: Analyze sales data and get AI suggestions (OLD METHOD)
*/
async analyzeSalesDataForOnboarding(tenantId: string, file: File): Promise<OnboardingAnalysisResult> {
// This method will use the new flow under the hood for backward compatibility
const validationResult = await this.validateFileAndExtractProducts(tenantId, file);
if (!validationResult.is_valid) {
throw new Error(`File validation failed: ${validationResult.validation_errors.map(e => e.message || e).join(', ')}`);
}
const suggestionsResult = await this.generateInventorySuggestions(tenantId, file, validationResult.product_list);
// Convert to legacy format
return {
total_products_found: suggestionsResult.total_products,
inventory_suggestions: suggestionsResult.suggestions,
business_model_analysis: suggestionsResult.business_model_analysis,
import_job_id: `legacy-${Date.now()}`,
status: 'completed',
processed_rows: validationResult.total_records,
errors: validationResult.validation_errors.map(e => e.message || String(e)),
warnings: validationResult.validation_warnings.map(w => w.message || String(w))
};
}
/**
* Get business model guidance based on analysis
*/