Add frontend order API
This commit is contained in:
173
frontend/src/api/services/orders.ts
Normal file
173
frontend/src/api/services/orders.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* Orders Service - API endpoints for Orders Service
|
||||
*
|
||||
* This service mirrors the backend API endpoints defined in:
|
||||
* services/orders/app/api/orders.py
|
||||
*/
|
||||
|
||||
import { apiClient } from '../client/apiClient';
|
||||
import {
|
||||
OrderResponse,
|
||||
OrderCreate,
|
||||
OrderUpdate,
|
||||
CustomerResponse,
|
||||
CustomerCreate,
|
||||
CustomerUpdate,
|
||||
OrdersDashboardSummary,
|
||||
DemandRequirements,
|
||||
BusinessModelDetection,
|
||||
ServiceStatus,
|
||||
GetOrdersParams,
|
||||
GetCustomersParams,
|
||||
UpdateOrderStatusParams,
|
||||
GetDemandRequirementsParams,
|
||||
} from '../types/orders';
|
||||
|
||||
export class OrdersService {
|
||||
// ===== Dashboard and Analytics Endpoints =====
|
||||
|
||||
/**
|
||||
* Get comprehensive dashboard summary for orders
|
||||
* GET /tenants/{tenant_id}/orders/dashboard-summary
|
||||
*/
|
||||
static async getDashboardSummary(tenantId: string): Promise<OrdersDashboardSummary> {
|
||||
return apiClient.get<OrdersDashboardSummary>(`/tenants/${tenantId}/orders/dashboard-summary`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get demand requirements for production planning
|
||||
* GET /tenants/{tenant_id}/orders/demand-requirements
|
||||
*/
|
||||
static async getDemandRequirements(params: GetDemandRequirementsParams): Promise<DemandRequirements> {
|
||||
const { tenant_id, target_date } = params;
|
||||
return apiClient.get<DemandRequirements>(
|
||||
`/tenants/${tenant_id}/orders/demand-requirements?target_date=${target_date}`
|
||||
);
|
||||
}
|
||||
|
||||
// ===== Order Management Endpoints =====
|
||||
|
||||
/**
|
||||
* Create a new customer order
|
||||
* POST /tenants/{tenant_id}/orders
|
||||
*/
|
||||
static async createOrder(orderData: OrderCreate): Promise<OrderResponse> {
|
||||
const { tenant_id, ...data } = orderData;
|
||||
return apiClient.post<OrderResponse>(`/tenants/${tenant_id}/orders`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get order details with items
|
||||
* GET /tenants/{tenant_id}/orders/{order_id}
|
||||
*/
|
||||
static async getOrder(tenantId: string, orderId: string): Promise<OrderResponse> {
|
||||
return apiClient.get<OrderResponse>(`/tenants/${tenantId}/orders/${orderId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get orders with filtering and pagination
|
||||
* GET /tenants/{tenant_id}/orders
|
||||
*/
|
||||
static async getOrders(params: GetOrdersParams): Promise<OrderResponse[]> {
|
||||
const { tenant_id, status_filter, start_date, end_date, skip = 0, limit = 100 } = params;
|
||||
|
||||
const queryParams = new URLSearchParams({
|
||||
skip: skip.toString(),
|
||||
limit: limit.toString(),
|
||||
});
|
||||
|
||||
if (status_filter) {
|
||||
queryParams.append('status_filter', status_filter);
|
||||
}
|
||||
if (start_date) {
|
||||
queryParams.append('start_date', start_date);
|
||||
}
|
||||
if (end_date) {
|
||||
queryParams.append('end_date', end_date);
|
||||
}
|
||||
|
||||
return apiClient.get<OrderResponse[]>(`/tenants/${tenant_id}/orders?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order status
|
||||
* PUT /tenants/{tenant_id}/orders/{order_id}/status
|
||||
*/
|
||||
static async updateOrderStatus(params: UpdateOrderStatusParams): Promise<OrderResponse> {
|
||||
const { tenant_id, order_id, new_status, reason } = params;
|
||||
|
||||
const queryParams = new URLSearchParams();
|
||||
if (reason) {
|
||||
queryParams.append('reason', reason);
|
||||
}
|
||||
|
||||
const url = `/tenants/${tenant_id}/orders/${order_id}/status${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
|
||||
|
||||
return apiClient.put<OrderResponse>(url, { status: new_status });
|
||||
}
|
||||
|
||||
// ===== Customer Management Endpoints =====
|
||||
|
||||
/**
|
||||
* Create a new customer
|
||||
* POST /tenants/{tenant_id}/customers
|
||||
*/
|
||||
static async createCustomer(customerData: CustomerCreate): Promise<CustomerResponse> {
|
||||
const { tenant_id, ...data } = customerData;
|
||||
return apiClient.post<CustomerResponse>(`/tenants/${tenant_id}/customers`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customers with filtering and pagination
|
||||
* GET /tenants/{tenant_id}/customers
|
||||
*/
|
||||
static async getCustomers(params: GetCustomersParams): Promise<CustomerResponse[]> {
|
||||
const { tenant_id, active_only = true, skip = 0, limit = 100 } = params;
|
||||
|
||||
const queryParams = new URLSearchParams({
|
||||
active_only: active_only.toString(),
|
||||
skip: skip.toString(),
|
||||
limit: limit.toString(),
|
||||
});
|
||||
|
||||
return apiClient.get<CustomerResponse[]>(`/tenants/${tenant_id}/customers?${queryParams.toString()}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer details
|
||||
* GET /tenants/{tenant_id}/customers/{customer_id}
|
||||
*/
|
||||
static async getCustomer(tenantId: string, customerId: string): Promise<CustomerResponse> {
|
||||
return apiClient.get<CustomerResponse>(`/tenants/${tenantId}/customers/${customerId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update customer details
|
||||
* PUT /tenants/{tenant_id}/customers/{customer_id}
|
||||
*/
|
||||
static async updateCustomer(tenantId: string, customerId: string, customerData: CustomerUpdate): Promise<CustomerResponse> {
|
||||
return apiClient.put<CustomerResponse>(`/tenants/${tenantId}/customers/${customerId}`, customerData);
|
||||
}
|
||||
|
||||
// ===== Business Intelligence Endpoints =====
|
||||
|
||||
/**
|
||||
* Detect business model based on order patterns
|
||||
* GET /tenants/{tenant_id}/orders/business-model
|
||||
*/
|
||||
static async detectBusinessModel(tenantId: string): Promise<BusinessModelDetection> {
|
||||
return apiClient.get<BusinessModelDetection>(`/tenants/${tenantId}/orders/business-model`);
|
||||
}
|
||||
|
||||
// ===== Health and Status Endpoints =====
|
||||
|
||||
/**
|
||||
* Get orders service status
|
||||
* GET /tenants/{tenant_id}/orders/status
|
||||
*/
|
||||
static async getServiceStatus(tenantId: string): Promise<ServiceStatus> {
|
||||
return apiClient.get<ServiceStatus>(`/tenants/${tenantId}/orders/status`);
|
||||
}
|
||||
}
|
||||
|
||||
export default OrdersService;
|
||||
Reference in New Issue
Block a user