Fix new services implementation 3

This commit is contained in:
Urtzi Alfaro
2025-08-14 16:47:34 +02:00
parent 0951547e92
commit 03737430ee
51 changed files with 657 additions and 982 deletions

View File

@@ -91,7 +91,8 @@ export class ForecastingService {
async getForecasts(
tenantId: string,
params?: BaseQueryParams & {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility - will need inventory service lookup
start_date?: string;
end_date?: string;
model_id?: string;
@@ -158,7 +159,8 @@ export class ForecastingService {
}
return forecastsArray.map((forecast: any) => ({
product_name: forecast.product_name,
inventory_product_id: forecast.inventory_product_id,
product_name: forecast.product_name, // Optional - for display
next_day_prediction: forecast.predicted_demand || 0,
next_week_avg: forecast.predicted_demand || 0,
trend_direction: 'stable' as const,
@@ -168,9 +170,10 @@ export class ForecastingService {
} catch (error) {
console.error('QuickForecasts API call failed, using fallback data:', error);
// Return mock data for common bakery products
// Return mock data for common bakery products (using mock inventory_product_ids)
return [
{
inventory_product_id: 'mock-pan-de-molde-001',
product_name: 'Pan de Molde',
next_day_prediction: 25,
next_week_avg: 175,
@@ -179,6 +182,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-baguettes-002',
product_name: 'Baguettes',
next_day_prediction: 20,
next_week_avg: 140,
@@ -187,6 +191,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-croissants-003',
product_name: 'Croissants',
next_day_prediction: 15,
next_week_avg: 105,
@@ -195,6 +200,7 @@ export class ForecastingService {
last_updated: new Date().toISOString()
},
{
inventory_product_id: 'mock-magdalenas-004',
product_name: 'Magdalenas',
next_day_prediction: 12,
next_week_avg: 84,
@@ -244,7 +250,8 @@ export class ForecastingService {
tenantId: string,
format: 'csv' | 'excel' | 'json',
params?: {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility
start_date?: string;
end_date?: string;
}
@@ -272,7 +279,8 @@ export class ForecastingService {
async getForecastAccuracy(
tenantId: string,
params?: {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility
model_id?: string;
start_date?: string;
end_date?: string;
@@ -280,7 +288,8 @@ export class ForecastingService {
): Promise<{
overall_accuracy: number;
product_accuracy: Array<{
product_name: string;
inventory_product_id: string;
product_name?: string; // Optional - for display
accuracy: number;
sample_size: number;
}>;

View File

@@ -139,7 +139,8 @@ export class SalesService {
params?: {
start_date?: string;
end_date?: string;
product_names?: string[];
inventory_product_ids?: string[]; // Primary way to filter by products
product_names?: string[]; // For backward compatibility - will need inventory service lookup
metrics?: string[];
}
): Promise<any> {

View File

@@ -176,7 +176,8 @@ export interface PurchaseOrderItem {
price_list_item_id?: string;
ingredient_id: string;
product_code?: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for display, populated by frontend from inventory service
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
@@ -207,7 +208,8 @@ export interface CreatePurchaseOrderRequest {
items: {
ingredient_id: string;
product_code?: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for backward compatibility
ordered_quantity: number;
unit_of_measure: string;
unit_price: number;
@@ -268,7 +270,8 @@ export interface DeliveryItem {
delivery_id: string;
purchase_order_item_id: string;
ingredient_id: string;
product_name: string;
inventory_product_id: string; // Reference to inventory service product
product_name?: string; // Optional - for display, populated by frontend from inventory service
ordered_quantity: number;
delivered_quantity: number;
accepted_quantity: number;

View File

@@ -101,7 +101,8 @@ export class TrainingService {
async getModels(
tenantId: string,
params?: BaseQueryParams & {
product_name?: string;
inventory_product_id?: string; // Primary way to filter by product
product_name?: string; // For backward compatibility - will need inventory service lookup
is_active?: boolean;
}
): Promise<PaginatedResponse<ModelInfo>> {