Add production APIs to frontend

This commit is contained in:
Urtzi Alfaro
2025-09-10 08:00:50 +02:00
parent aff644d793
commit 44b789f523
4 changed files with 657 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
import { apiClient } from '../client';
import type {
ProductionBatchCreate,
ProductionBatchStatusUpdate,
ProductionBatchResponse,
ProductionBatchListResponse,
ProductionDashboardSummary,
DailyProductionRequirements,
ProductionScheduleData,
ProductionCapacityStatus,
ProductionRequirements,
ProductionYieldMetrics,
} from '../types/production';
export class ProductionService {
private readonly baseUrl = '/production';
getDashboardSummary(tenantId: string): Promise<ProductionDashboardSummary> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard-summary`);
}
getDailyRequirements(tenantId: string, date?: string): Promise<DailyProductionRequirements> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/daily-requirements`, { params });
}
getProductionRequirements(tenantId: string, date?: string): Promise<ProductionRequirements> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/requirements`, { params });
}
createProductionBatch(tenantId: string, batchData: ProductionBatchCreate): Promise<ProductionBatchResponse> {
return apiClient.post(`/tenants/${tenantId}${this.baseUrl}/batches`, batchData);
}
getActiveBatches(tenantId: string): Promise<ProductionBatchListResponse> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/batches/active`);
}
getBatchDetails(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
}
updateBatchStatus(
tenantId: string,
batchId: string,
statusUpdate: ProductionBatchStatusUpdate
): Promise<ProductionBatchResponse> {
return apiClient.put(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/status`, statusUpdate);
}
getProductionSchedule(
tenantId: string,
startDate?: string,
endDate?: string
): Promise<ProductionScheduleData> {
const params: Record<string, string> = {};
if (startDate) params.start_date = startDate;
if (endDate) params.end_date = endDate;
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/schedule`, { params });
}
getCapacityStatus(tenantId: string, date?: string): Promise<ProductionCapacityStatus> {
const params = date ? { date } : {};
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/capacity/status`, { params });
}
getYieldMetrics(
tenantId: string,
startDate: string,
endDate: string
): Promise<ProductionYieldMetrics> {
const params = { start_date: startDate, end_date: endDate };
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/metrics/yield`, { params });
}
}
export const productionService = new ProductionService();