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

@@ -392,6 +392,57 @@ private buildURL(endpoint: string): string {
return this.request<T>(endpoint, { ...config, method: 'DELETE' });
}
/**
* Raw request that returns the Response object for binary data
*/
async getRaw(endpoint: string, config?: RequestConfig): Promise<Response> {
const url = this.buildURL(endpoint);
const modifiedConfig = await this.applyRequestInterceptors(config || {});
const headers: Record<string, string> = {
...modifiedConfig.headers,
};
const fetchConfig: RequestInit = {
method: 'GET',
headers,
signal: AbortSignal.timeout(modifiedConfig.timeout || apiConfig.timeout),
};
// Add query parameters
const urlWithParams = new URL(url);
if (modifiedConfig.params) {
Object.entries(modifiedConfig.params).forEach(([key, value]) => {
if (value !== undefined && value !== null) {
urlWithParams.searchParams.append(key, String(value));
}
});
}
const response = await fetch(urlWithParams.toString(), fetchConfig);
if (!response.ok) {
const errorText = await response.text();
let errorData: ApiError;
try {
errorData = JSON.parse(errorText);
} catch {
errorData = {
message: `HTTP ${response.status}: ${response.statusText}`,
detail: errorText,
code: `HTTP_${response.status}`,
};
}
const error = new Error(errorData.message || 'Request failed');
(error as any).response = { status: response.status, data: errorData };
throw error;
}
return response;
}
/**
* File upload with progress tracking
*/

View File

@@ -88,7 +88,7 @@ interface UseInventoryItemReturn {
// ========== MAIN INVENTORY HOOK ==========
export const useInventory = (autoLoad = true): UseInventoryReturn => {
const tenantId = useTenantId();
const { tenantId } = useTenantId();
// State
const [items, setItems] = useState<InventoryItem[]>([]);
@@ -373,7 +373,7 @@ export const useInventory = (autoLoad = true): UseInventoryReturn => {
// ========== DASHBOARD HOOK ==========
export const useInventoryDashboard = (): UseInventoryDashboardReturn => {
const tenantId = useTenantId();
const { tenantId } = useTenantId();
const [dashboardData, setDashboardData] = useState<InventoryDashboardData | null>(null);
const [alerts, setAlerts] = useState<StockAlert[]>([]);
const [isLoading, setIsLoading] = useState(false);
@@ -419,7 +419,7 @@ export const useInventoryDashboard = (): UseInventoryDashboardReturn => {
// ========== SINGLE ITEM HOOK ==========
export const useInventoryItem = (itemId: string): UseInventoryItemReturn => {
const tenantId = useTenantId();
const { tenantId } = useTenantId();
const [item, setItem] = useState<InventoryItem | null>(null);
const [stockLevel, setStockLevel] = useState<StockLevel | null>(null);
const [recentMovements, setRecentMovements] = useState<StockMovement[]>([]);

View File

@@ -22,6 +22,23 @@ import {
} from '../services/suppliers.service';
import { useAuth } from './useAuth';
// Re-export types for component use
export type {
Supplier,
SupplierSummary,
CreateSupplierRequest,
UpdateSupplierRequest,
SupplierSearchParams,
SupplierStatistics,
PurchaseOrder,
CreatePurchaseOrderRequest,
PurchaseOrderSearchParams,
PurchaseOrderStatistics,
Delivery,
DeliverySearchParams,
DeliveryPerformanceStats
} from '../services/suppliers.service';
const suppliersService = new SuppliersService();
// ============================================================================
@@ -196,13 +213,13 @@ export function useSuppliers(): UseSuppliers {
// Create supplier
const createSupplier = useCallback(async (data: CreateSupplierRequest): Promise<Supplier | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setIsCreating(true);
setError(null);
const supplier = await suppliersService.createSupplier(user.tenant_id, user.user_id, data);
const supplier = await suppliersService.createSupplier(user.tenant_id, user.id, data);
// Refresh suppliers list
await loadSuppliers(currentParams);
@@ -217,17 +234,17 @@ export function useSuppliers(): UseSuppliers {
} finally {
setIsCreating(false);
}
}, [user?.tenant_id, user?.user_id, loadSuppliers, loadStatistics, currentParams]);
}, [user?.tenant_id, user?.id, loadSuppliers, loadStatistics, currentParams]);
// Update supplier
const updateSupplier = useCallback(async (supplierId: string, data: UpdateSupplierRequest): Promise<Supplier | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setIsUpdating(true);
setError(null);
const updatedSupplier = await suppliersService.updateSupplier(user.tenant_id, user.user_id, supplierId, data);
const updatedSupplier = await suppliersService.updateSupplier(user.tenant_id, user.id, supplierId, data);
// Update current supplier if it's the one being edited
if (supplier?.id === supplierId) {
@@ -246,7 +263,7 @@ export function useSuppliers(): UseSuppliers {
} finally {
setIsUpdating(false);
}
}, [user?.tenant_id, user?.user_id, supplier?.id, loadSuppliers, currentParams]);
}, [user?.tenant_id, user?.id, supplier?.id, loadSuppliers, currentParams]);
// Delete supplier
const deleteSupplier = useCallback(async (supplierId: string): Promise<boolean> => {
@@ -277,12 +294,12 @@ export function useSuppliers(): UseSuppliers {
// Approve/reject supplier
const approveSupplier = useCallback(async (supplierId: string, action: 'approve' | 'reject', notes?: string): Promise<Supplier | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedSupplier = await suppliersService.approveSupplier(user.tenant_id, user.user_id, supplierId, action, notes);
const updatedSupplier = await suppliersService.approveSupplier(user.tenant_id, user.id, supplierId, action, notes);
// Update current supplier if it's the one being approved/rejected
if (supplier?.id === supplierId) {
@@ -300,7 +317,7 @@ export function useSuppliers(): UseSuppliers {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, supplier?.id, loadSuppliers, loadStatistics, currentParams]);
}, [user?.tenant_id, user?.id, supplier?.id, loadSuppliers, loadStatistics, currentParams]);
// Clear error
const clearError = useCallback(() => {
@@ -504,13 +521,13 @@ export function usePurchaseOrders(): UsePurchaseOrders {
}, [user?.tenant_id]);
const createPurchaseOrder = useCallback(async (data: CreatePurchaseOrderRequest): Promise<PurchaseOrder | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setIsCreating(true);
setError(null);
const order = await suppliersService.createPurchaseOrder(user.tenant_id, user.user_id, data);
const order = await suppliersService.createPurchaseOrder(user.tenant_id, user.id, data);
// Refresh orders list
await loadPurchaseOrders(currentParams);
@@ -525,15 +542,15 @@ export function usePurchaseOrders(): UsePurchaseOrders {
} finally {
setIsCreating(false);
}
}, [user?.tenant_id, user?.user_id, loadPurchaseOrders, loadStatistics, currentParams]);
}, [user?.tenant_id, user?.id, loadPurchaseOrders, loadStatistics, currentParams]);
const updateOrderStatus = useCallback(async (poId: string, status: string, notes?: string): Promise<PurchaseOrder | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedOrder = await suppliersService.updatePurchaseOrderStatus(user.tenant_id, user.user_id, poId, status, notes);
const updatedOrder = await suppliersService.updatePurchaseOrderStatus(user.tenant_id, user.id, poId, status, notes);
if (purchaseOrder?.id === poId) {
setPurchaseOrder(updatedOrder);
@@ -548,15 +565,15 @@ export function usePurchaseOrders(): UsePurchaseOrders {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
}, [user?.tenant_id, user?.id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
const approveOrder = useCallback(async (poId: string, action: 'approve' | 'reject', notes?: string): Promise<PurchaseOrder | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedOrder = await suppliersService.approvePurchaseOrder(user.tenant_id, user.user_id, poId, action, notes);
const updatedOrder = await suppliersService.approvePurchaseOrder(user.tenant_id, user.id, poId, action, notes);
if (purchaseOrder?.id === poId) {
setPurchaseOrder(updatedOrder);
@@ -572,15 +589,15 @@ export function usePurchaseOrders(): UsePurchaseOrders {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, purchaseOrder?.id, loadPurchaseOrders, loadOrdersRequiringApproval, currentParams]);
}, [user?.tenant_id, user?.id, purchaseOrder?.id, loadPurchaseOrders, loadOrdersRequiringApproval, currentParams]);
const sendToSupplier = useCallback(async (poId: string, sendEmail: boolean = true): Promise<PurchaseOrder | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedOrder = await suppliersService.sendToSupplier(user.tenant_id, user.user_id, poId, sendEmail);
const updatedOrder = await suppliersService.sendToSupplier(user.tenant_id, user.id, poId, sendEmail);
if (purchaseOrder?.id === poId) {
setPurchaseOrder(updatedOrder);
@@ -595,15 +612,15 @@ export function usePurchaseOrders(): UsePurchaseOrders {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
}, [user?.tenant_id, user?.id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
const cancelOrder = useCallback(async (poId: string, reason: string): Promise<PurchaseOrder | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedOrder = await suppliersService.cancelPurchaseOrder(user.tenant_id, user.user_id, poId, reason);
const updatedOrder = await suppliersService.cancelPurchaseOrder(user.tenant_id, user.id, poId, reason);
if (purchaseOrder?.id === poId) {
setPurchaseOrder(updatedOrder);
@@ -618,7 +635,7 @@ export function usePurchaseOrders(): UsePurchaseOrders {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
}, [user?.tenant_id, user?.id, purchaseOrder?.id, loadPurchaseOrders, currentParams]);
const clearError = useCallback(() => {
setError(null);
@@ -804,12 +821,12 @@ export function useDeliveries(): UseDeliveries {
}, [user?.tenant_id]);
const updateDeliveryStatus = useCallback(async (deliveryId: string, status: string, notes?: string): Promise<Delivery | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedDelivery = await suppliersService.updateDeliveryStatus(user.tenant_id, user.user_id, deliveryId, status, notes);
const updatedDelivery = await suppliersService.updateDeliveryStatus(user.tenant_id, user.id, deliveryId, status, notes);
if (delivery?.id === deliveryId) {
setDelivery(updatedDelivery);
@@ -824,15 +841,15 @@ export function useDeliveries(): UseDeliveries {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, delivery?.id, loadDeliveries, currentParams]);
}, [user?.tenant_id, user?.id, delivery?.id, loadDeliveries, currentParams]);
const receiveDelivery = useCallback(async (deliveryId: string, receiptData: any): Promise<Delivery | null> => {
if (!user?.tenant_id || !user?.user_id) return null;
if (!user?.tenant_id || !user?.id) return null;
try {
setError(null);
const updatedDelivery = await suppliersService.receiveDelivery(user.tenant_id, user.user_id, deliveryId, receiptData);
const updatedDelivery = await suppliersService.receiveDelivery(user.tenant_id, user.id, deliveryId, receiptData);
if (delivery?.id === deliveryId) {
setDelivery(updatedDelivery);
@@ -847,7 +864,7 @@ export function useDeliveries(): UseDeliveries {
setError(errorMessage);
return null;
}
}, [user?.tenant_id, user?.user_id, delivery?.id, loadDeliveries, currentParams]);
}, [user?.tenant_id, user?.id, delivery?.id, loadDeliveries, currentParams]);
const clearError = useCallback(() => {
setError(null);

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;
}
}

View File

@@ -39,4 +39,16 @@ export interface BaseQueryParams {
search?: string;
sort?: string;
order?: 'asc' | 'desc';
}
export interface CreateResponse<T = any> {
data: T;
message?: string;
status: string;
}
export interface UpdateResponse<T = any> {
data: T;
message?: string;
status: string;
}

View File

@@ -18,6 +18,15 @@ export interface SalesData {
source: string;
created_at: string;
external_factors?: ExternalFactors;
// Additional properties used by components
sales_channel?: string;
is_validated?: boolean;
cost_of_goods?: number;
revenue?: number;
quantity_sold?: number;
inventory_product_id?: string;
discount_applied?: number;
weather_condition?: string;
}
export interface SalesValidationResult {
@@ -53,6 +62,10 @@ export interface SalesDataQuery extends BaseQueryParams {
max_quantity?: number;
min_revenue?: number;
max_revenue?: number;
search_term?: string;
sales_channel?: string;
inventory_product_id?: string;
is_validated?: boolean;
}
export interface SalesDataImport {

View File

@@ -14,6 +14,8 @@ export interface TenantInfo {
settings?: TenantSettings;
subscription?: TenantSubscription;
location?: TenantLocation;
business_type?: 'bakery' | 'coffee_shop' | 'pastry_shop' | 'restaurant';
business_model?: 'individual_bakery' | 'central_baker_satellite' | 'retail_bakery' | 'hybrid_bakery';
}
export interface TenantSettings {
@@ -62,7 +64,8 @@ export interface TenantSubscription {
export interface TenantCreate {
name: string;
address?: string;
business_type?: 'individual' | 'central_workshop';
business_type?: 'bakery' | 'coffee_shop' | 'pastry_shop' | 'restaurant';
business_model?: 'individual_bakery' | 'central_baker_satellite' | 'retail_bakery' | 'hybrid_bakery';
postal_code: string;
phone: string;
description?: string;

View File

@@ -120,8 +120,8 @@ export const useTrainingWebSocket = (jobId: string, tenantId?: string) => {
const config = {
url: actualTenantId
? `ws://localhost:8002/api/v1/ws/tenants/${actualTenantId}/training/jobs/${jobId}/live`
: `ws://localhost:8002/api/v1/ws/tenants/unknown/training/jobs/${jobId}/live`,
? `ws://localhost:8000/api/v1/ws/tenants/${actualTenantId}/training/jobs/${jobId}/live`
: `ws://localhost:8000/api/v1/ws/tenants/unknown/training/jobs/${jobId}/live`,
reconnect: true,
reconnectInterval: 3000,
maxReconnectAttempts: 10