Add frontend imporvements
This commit is contained in:
132
frontend/src/api/services/forecasting.ts
Normal file
132
frontend/src/api/services/forecasting.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* Forecasting Service
|
||||
* API calls for forecasting service endpoints
|
||||
*/
|
||||
|
||||
import { apiClient } from '../client/apiClient';
|
||||
import {
|
||||
ForecastRequest,
|
||||
ForecastResponse,
|
||||
BatchForecastRequest,
|
||||
BatchForecastResponse,
|
||||
ForecastListResponse,
|
||||
ForecastByIdResponse,
|
||||
ForecastStatistics,
|
||||
DeleteForecastResponse,
|
||||
GetForecastsParams,
|
||||
ForecastingHealthResponse,
|
||||
} from '../types/forecasting';
|
||||
|
||||
export class ForecastingService {
|
||||
private readonly baseUrl = '/forecasts';
|
||||
|
||||
/**
|
||||
* Generate a single product forecast
|
||||
* POST /tenants/{tenant_id}/forecasts/single
|
||||
*/
|
||||
async createSingleForecast(
|
||||
tenantId: string,
|
||||
request: ForecastRequest
|
||||
): Promise<ForecastResponse> {
|
||||
return apiClient.post<ForecastResponse, ForecastRequest>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/single`,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate batch forecasts for multiple products
|
||||
* POST /tenants/{tenant_id}/forecasts/batch
|
||||
*/
|
||||
async createBatchForecast(
|
||||
tenantId: string,
|
||||
request: BatchForecastRequest
|
||||
): Promise<BatchForecastResponse> {
|
||||
return apiClient.post<BatchForecastResponse, BatchForecastRequest>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batch`,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tenant forecasts with filtering and pagination
|
||||
* GET /tenants/{tenant_id}/forecasts
|
||||
*/
|
||||
async getTenantForecasts(
|
||||
tenantId: string,
|
||||
params?: GetForecastsParams
|
||||
): Promise<ForecastListResponse> {
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
if (params?.inventory_product_id) {
|
||||
searchParams.append('inventory_product_id', params.inventory_product_id);
|
||||
}
|
||||
if (params?.start_date) {
|
||||
searchParams.append('start_date', params.start_date);
|
||||
}
|
||||
if (params?.end_date) {
|
||||
searchParams.append('end_date', params.end_date);
|
||||
}
|
||||
if (params?.skip !== undefined) {
|
||||
searchParams.append('skip', params.skip.toString());
|
||||
}
|
||||
if (params?.limit !== undefined) {
|
||||
searchParams.append('limit', params.limit.toString());
|
||||
}
|
||||
|
||||
const queryString = searchParams.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get<ForecastListResponse>(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific forecast by ID
|
||||
* GET /tenants/{tenant_id}/forecasts/{forecast_id}
|
||||
*/
|
||||
async getForecastById(
|
||||
tenantId: string,
|
||||
forecastId: string
|
||||
): Promise<ForecastByIdResponse> {
|
||||
return apiClient.get<ForecastByIdResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/${forecastId}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a forecast
|
||||
* DELETE /tenants/{tenant_id}/forecasts/{forecast_id}
|
||||
*/
|
||||
async deleteForecast(
|
||||
tenantId: string,
|
||||
forecastId: string
|
||||
): Promise<DeleteForecastResponse> {
|
||||
return apiClient.delete<DeleteForecastResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/${forecastId}`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comprehensive forecast statistics
|
||||
* GET /tenants/{tenant_id}/forecasts/statistics
|
||||
*/
|
||||
async getForecastStatistics(
|
||||
tenantId: string
|
||||
): Promise<ForecastStatistics> {
|
||||
return apiClient.get<ForecastStatistics>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/statistics`
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Health check for forecasting service
|
||||
* GET /health
|
||||
*/
|
||||
async getHealthCheck(): Promise<ForecastingHealthResponse> {
|
||||
return apiClient.get<ForecastingHealthResponse>('/health');
|
||||
}
|
||||
}
|
||||
|
||||
// Export singleton instance
|
||||
export const forecastingService = new ForecastingService();
|
||||
export default forecastingService;
|
||||
@@ -83,7 +83,7 @@ export class InventoryService {
|
||||
}
|
||||
|
||||
async getLowStockIngredients(tenantId: string): Promise<IngredientResponse[]> {
|
||||
return apiClient.get<IngredientResponse[]>(`${this.baseUrl}/${tenantId}/ingredients/low-stock`);
|
||||
return apiClient.get<IngredientResponse[]>(`${this.baseUrl}/${tenantId}/stock/low-stock`);
|
||||
}
|
||||
|
||||
// Stock Management
|
||||
@@ -104,7 +104,7 @@ export class InventoryService {
|
||||
queryParams.append('include_unavailable', includeUnavailable.toString());
|
||||
|
||||
return apiClient.get<StockResponse[]>(
|
||||
`${this.baseUrl}/${tenantId}/stock/ingredient/${ingredientId}?${queryParams.toString()}`
|
||||
`${this.baseUrl}/${tenantId}/ingredients/${ingredientId}/stock?${queryParams.toString()}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -218,8 +218,8 @@ export class InventoryService {
|
||||
if (endDate) queryParams.append('end_date', endDate);
|
||||
|
||||
const url = queryParams.toString()
|
||||
? `${this.baseUrl}/${tenantId}/inventory/analytics?${queryParams.toString()}`
|
||||
: `${this.baseUrl}/${tenantId}/inventory/analytics`;
|
||||
? `${this.baseUrl}/${tenantId}/dashboard/analytics?${queryParams.toString()}`
|
||||
: `${this.baseUrl}/${tenantId}/dashboard/analytics`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user