Fix new services implementation 2

This commit is contained in:
Urtzi Alfaro
2025-08-14 13:26:59 +02:00
parent 262b3dc9c4
commit 0951547e92
39 changed files with 1203 additions and 917 deletions

View File

@@ -43,6 +43,7 @@ export interface InventoryItem {
supplier?: string;
notes?: string;
barcode?: string;
sku?: string;
cost_per_unit?: number;
is_active: boolean;
created_at: string;

View File

@@ -211,7 +211,20 @@ export class OnboardingService {
suggestions: suggestions.map(s => ({
suggestion_id: s.suggestion_id,
approved: s.user_approved ?? true,
modifications: s.user_modifications || {}
modifications: s.user_modifications || {},
// Include full suggestion data for backend processing
original_name: s.original_name,
suggested_name: s.suggested_name,
product_type: s.product_type,
category: s.category,
unit_of_measure: s.unit_of_measure,
confidence_score: s.confidence_score,
estimated_shelf_life_days: s.estimated_shelf_life_days,
requires_refrigeration: s.requires_refrigeration,
requires_freezing: s.requires_freezing,
is_seasonal: s.is_seasonal,
suggested_supplier: s.suggested_supplier,
notes: s.notes
}))
});
}

View File

@@ -367,14 +367,14 @@ export class RecipesService {
headers: { 'X-Tenant-ID': tenantId },
params
});
return response.data;
return response;
}
async getRecipe(tenantId: string, recipeId: string): Promise<Recipe> {
const response = await apiClient.get<Recipe>(`${this.baseUrl}/recipes/${recipeId}`, {
headers: { 'X-Tenant-ID': tenantId }
});
return response.data;
return response;
}
async createRecipe(tenantId: string, userId: string, data: CreateRecipeRequest): Promise<Recipe> {
@@ -384,7 +384,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async updateRecipe(tenantId: string, userId: string, recipeId: string, data: UpdateRecipeRequest): Promise<Recipe> {
@@ -394,7 +394,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async deleteRecipe(tenantId: string, recipeId: string): Promise<void> {
@@ -413,7 +413,7 @@ export class RecipesService {
}
}
);
return response.data;
return response;
}
async activateRecipe(tenantId: string, userId: string, recipeId: string): Promise<Recipe> {
@@ -423,7 +423,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async checkRecipeFeasibility(tenantId: string, recipeId: string, batchMultiplier: number = 1.0): Promise<RecipeFeasibility> {
@@ -431,21 +431,21 @@ export class RecipesService {
headers: { 'X-Tenant-ID': tenantId },
params: { batch_multiplier: batchMultiplier }
});
return response.data;
return response;
}
async getRecipeStatistics(tenantId: string): Promise<RecipeStatistics> {
const response = await apiClient.get<RecipeStatistics>(`${this.baseUrl}/recipes/statistics/dashboard`, {
headers: { 'X-Tenant-ID': tenantId }
});
return response.data;
return response;
}
async getRecipeCategories(tenantId: string): Promise<string[]> {
const response = await apiClient.get<{ categories: string[] }>(`${this.baseUrl}/recipes/categories/list`, {
headers: { 'X-Tenant-ID': tenantId }
});
return response.data.categories;
return response.categories;
}
// Production Management
@@ -454,14 +454,14 @@ export class RecipesService {
headers: { 'X-Tenant-ID': tenantId },
params
});
return response.data;
return response;
}
async getProductionBatch(tenantId: string, batchId: string): Promise<ProductionBatch> {
const response = await apiClient.get<ProductionBatch>(`${this.baseUrl}/production/batches/${batchId}`, {
headers: { 'X-Tenant-ID': tenantId }
});
return response.data;
return response;
}
async createProductionBatch(tenantId: string, userId: string, data: CreateProductionBatchRequest): Promise<ProductionBatch> {
@@ -471,7 +471,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async updateProductionBatch(tenantId: string, userId: string, batchId: string, data: UpdateProductionBatchRequest): Promise<ProductionBatch> {
@@ -481,7 +481,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async deleteProductionBatch(tenantId: string, batchId: string): Promise<void> {
@@ -494,7 +494,7 @@ export class RecipesService {
const response = await apiClient.get<ProductionBatch[]>(`${this.baseUrl}/production/batches/active/list`, {
headers: { 'X-Tenant-ID': tenantId }
});
return response.data;
return response;
}
async startProductionBatch(tenantId: string, userId: string, batchId: string, data: {
@@ -519,7 +519,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async completeProductionBatch(tenantId: string, userId: string, batchId: string, data: {
@@ -538,7 +538,7 @@ export class RecipesService {
'X-User-ID': userId
}
});
return response.data;
return response;
}
async getProductionStatistics(tenantId: string, startDate?: string, endDate?: string): Promise<ProductionStatistics> {
@@ -546,6 +546,6 @@ export class RecipesService {
headers: { 'X-Tenant-ID': tenantId },
params: { start_date: startDate, end_date: endDate }
});
return response.data;
return response;
}
}

View File

@@ -361,7 +361,7 @@ export class SuppliersService {
`${this.baseUrl}?${searchParams.toString()}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getSupplier(tenantId: string, supplierId: string): Promise<Supplier> {
@@ -369,7 +369,7 @@ export class SuppliersService {
`${this.baseUrl}/${supplierId}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async createSupplier(tenantId: string, userId: string, data: CreateSupplierRequest): Promise<Supplier> {
@@ -378,7 +378,7 @@ export class SuppliersService {
data,
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async updateSupplier(tenantId: string, userId: string, supplierId: string, data: UpdateSupplierRequest): Promise<Supplier> {
@@ -387,7 +387,7 @@ export class SuppliersService {
data,
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async deleteSupplier(tenantId: string, supplierId: string): Promise<void> {
@@ -403,7 +403,7 @@ export class SuppliersService {
{ action, notes },
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
// Supplier Analytics & Lists
@@ -412,7 +412,7 @@ export class SuppliersService {
`${this.baseUrl}/statistics`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getActiveSuppliers(tenantId: string): Promise<SupplierSummary[]> {
@@ -420,7 +420,7 @@ export class SuppliersService {
`${this.baseUrl}/active`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getTopSuppliers(tenantId: string, limit: number = 10): Promise<SupplierSummary[]> {
@@ -428,7 +428,7 @@ export class SuppliersService {
`${this.baseUrl}/top?limit=${limit}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getSuppliersByType(tenantId: string, supplierType: string): Promise<SupplierSummary[]> {
@@ -436,7 +436,7 @@ export class SuppliersService {
`${this.baseUrl}/types/${supplierType}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getSuppliersNeedingReview(tenantId: string, daysSinceLastOrder: number = 30): Promise<SupplierSummary[]> {
@@ -444,7 +444,7 @@ export class SuppliersService {
`${this.baseUrl}/pending-review?days_since_last_order=${daysSinceLastOrder}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
// Purchase Orders
@@ -463,7 +463,7 @@ export class SuppliersService {
`/api/v1/purchase-orders?${searchParams.toString()}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getPurchaseOrder(tenantId: string, poId: string): Promise<PurchaseOrder> {
@@ -471,7 +471,7 @@ export class SuppliersService {
`/api/v1/purchase-orders/${poId}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async createPurchaseOrder(tenantId: string, userId: string, data: CreatePurchaseOrderRequest): Promise<PurchaseOrder> {
@@ -480,7 +480,7 @@ export class SuppliersService {
data,
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async updatePurchaseOrderStatus(tenantId: string, userId: string, poId: string, status: string, notes?: string): Promise<PurchaseOrder> {
@@ -489,7 +489,7 @@ export class SuppliersService {
{ status, notes },
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async approvePurchaseOrder(tenantId: string, userId: string, poId: string, action: 'approve' | 'reject', notes?: string): Promise<PurchaseOrder> {
@@ -498,7 +498,7 @@ export class SuppliersService {
{ action, notes },
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async sendToSupplier(tenantId: string, userId: string, poId: string, sendEmail: boolean = true): Promise<PurchaseOrder> {
@@ -507,7 +507,7 @@ export class SuppliersService {
{},
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async cancelPurchaseOrder(tenantId: string, userId: string, poId: string, reason: string): Promise<PurchaseOrder> {
@@ -516,7 +516,7 @@ export class SuppliersService {
{},
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async getPurchaseOrderStatistics(tenantId: string): Promise<PurchaseOrderStatistics> {
@@ -524,7 +524,7 @@ export class SuppliersService {
'/api/v1/purchase-orders/statistics',
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getOrdersRequiringApproval(tenantId: string): Promise<PurchaseOrder[]> {
@@ -532,7 +532,7 @@ export class SuppliersService {
'/api/v1/purchase-orders/pending-approval',
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getOverdueOrders(tenantId: string): Promise<PurchaseOrder[]> {
@@ -540,7 +540,7 @@ export class SuppliersService {
'/api/v1/purchase-orders/overdue',
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
// Deliveries
@@ -558,7 +558,7 @@ export class SuppliersService {
`/api/v1/deliveries?${searchParams.toString()}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getDelivery(tenantId: string, deliveryId: string): Promise<Delivery> {
@@ -566,7 +566,7 @@ export class SuppliersService {
`/api/v1/deliveries/${deliveryId}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getTodaysDeliveries(tenantId: string): Promise<Delivery[]> {
@@ -574,7 +574,7 @@ export class SuppliersService {
'/api/v1/deliveries/today',
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async getOverdueDeliveries(tenantId: string): Promise<Delivery[]> {
@@ -582,7 +582,7 @@ export class SuppliersService {
'/api/v1/deliveries/overdue',
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
async updateDeliveryStatus(tenantId: string, userId: string, deliveryId: string, status: string, notes?: string): Promise<Delivery> {
@@ -591,7 +591,7 @@ export class SuppliersService {
{ status, notes, update_timestamps: true },
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async receiveDelivery(tenantId: string, userId: string, deliveryId: string, receiptData: {
@@ -605,7 +605,7 @@ export class SuppliersService {
receiptData,
{ headers: { 'X-Tenant-ID': tenantId, 'X-User-ID': userId } }
);
return response.data;
return response;
}
async getDeliveryPerformanceStats(tenantId: string, daysBack: number = 30, supplierId?: string): Promise<DeliveryPerformanceStats> {
@@ -617,6 +617,6 @@ export class SuppliersService {
`/api/v1/deliveries/performance-stats?${params.toString()}`,
{ headers: { 'X-Tenant-ID': tenantId } }
);
return response.data;
return response;
}
}