Start integrating the onboarding flow with backend 4
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
TrainingCompletedMessage,
|
||||
TrainingErrorMessage
|
||||
} from '../../../../services/realtime/websocket.service';
|
||||
import { trainingService } from '../../../../services/api/training.service';
|
||||
|
||||
interface TrainingMetrics {
|
||||
accuracy: number;
|
||||
@@ -35,44 +36,7 @@ interface TrainingJob {
|
||||
metrics?: TrainingMetrics;
|
||||
}
|
||||
|
||||
// Real training service using backend APIs
|
||||
class TrainingApiService {
|
||||
private async apiCall(endpoint: string, options: RequestInit = {}) {
|
||||
const response = await fetch(`/api${endpoint}`, {
|
||||
...options,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`API call failed: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async startTrainingJob(tenantId: string, startDate?: string, endDate?: string): Promise<TrainingJob> {
|
||||
return this.apiCall(`/tenants/${tenantId}/training/jobs`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async getTrainingJob(tenantId: string, jobId: string): Promise<TrainingJob> {
|
||||
return this.apiCall(`/tenants/${tenantId}/training/jobs/${jobId}`);
|
||||
}
|
||||
|
||||
async getTrainingJobs(tenantId: string): Promise<TrainingJob[]> {
|
||||
return this.apiCall(`/tenants/${tenantId}/training/jobs`);
|
||||
}
|
||||
}
|
||||
|
||||
const trainingService = new TrainingApiService();
|
||||
// Using the proper training service from services/api/training.service.ts
|
||||
|
||||
export const MLTrainingStep: React.FC<OnboardingStepProps> = ({
|
||||
data,
|
||||
@@ -114,13 +78,25 @@ export const MLTrainingStep: React.FC<OnboardingStepProps> = ({
|
||||
console.log('MLTrainingStep - dataProcessingData:', dataProcessingData);
|
||||
console.log('MLTrainingStep - reviewData:', reviewData);
|
||||
console.log('MLTrainingStep - inventoryData:', inventoryData);
|
||||
console.log('MLTrainingStep - inventoryData.salesImportResult:', inventoryData?.salesImportResult);
|
||||
|
||||
// Check if sales data was processed
|
||||
const hasProcessingResults = dataProcessingData?.processingResults &&
|
||||
dataProcessingData.processingResults.is_valid &&
|
||||
dataProcessingData.processingResults.total_records > 0;
|
||||
|
||||
// Check if sales data was imported (required for training)
|
||||
const hasImportResults = inventoryData?.salesImportResult &&
|
||||
(inventoryData.salesImportResult.records_created > 0 ||
|
||||
inventoryData.salesImportResult.success === true ||
|
||||
inventoryData.salesImportResult.imported === true);
|
||||
|
||||
if (!hasProcessingResults) {
|
||||
missingItems.push('Datos de ventas validados');
|
||||
}
|
||||
|
||||
// Sales data must be imported for ML training to work
|
||||
if (!hasImportResults) {
|
||||
missingItems.push('Datos de ventas importados');
|
||||
}
|
||||
|
||||
@@ -152,6 +128,7 @@ export const MLTrainingStep: React.FC<OnboardingStepProps> = ({
|
||||
isValid: missingItems.length === 0,
|
||||
missingItems,
|
||||
hasProcessingResults,
|
||||
hasImportResults,
|
||||
hasApprovedProducts,
|
||||
hasInventoryConfig
|
||||
});
|
||||
@@ -205,7 +182,11 @@ export const MLTrainingStep: React.FC<OnboardingStepProps> = ({
|
||||
try {
|
||||
// Start training job
|
||||
addLog('Iniciando trabajo de entrenamiento ML...', 'info');
|
||||
const job = await trainingService.startTrainingJob(tenantId);
|
||||
const response = await trainingService.createTrainingJob({
|
||||
start_date: undefined,
|
||||
end_date: undefined
|
||||
});
|
||||
const job = response.data;
|
||||
|
||||
setCurrentJob(job);
|
||||
setTrainingStatus('training');
|
||||
|
||||
Reference in New Issue
Block a user