Update analytics-service.ts

This commit is contained in:
g
2026-01-12 04:29:47 +00:00
parent 6eeed4267a
commit 198b9a82ff

View File

@@ -424,6 +424,23 @@ export interface PredictionsOverview {
message?: string;
}
export interface BatchPredictionsResponse {
success: boolean;
storeId?: string;
historicalPeriod?: number;
horizons?: number[];
simulationFactors?: number[];
predictions?: {
[horizon: string]: {
[simulationFactor: string]: PredictionsOverview;
};
};
totalEntries?: number;
generatedAt?: string;
message?: string;
}
// Prediction Service Functions
/**
@@ -546,3 +563,28 @@ export const getPredictionsOverviewWithStore = async (
const storeId = getStoreIdForUser();
return getPredictionsOverview(daysAhead, period, storeId, simulation);
};
/**
* Get all cached predictions in one request (for client-side switching)
* @param period Historical period in days (default: 90)
* @param storeId Optional storeId for staff users
*/
export const getBatchPredictions = async (
period: number = 90,
storeId?: string,
): Promise<BatchPredictionsResponse> => {
const params = new URLSearchParams({
period: period.toString(),
});
if (storeId) params.append("storeId", storeId);
const url = `/analytics/predictions/batch?${params.toString()}`;
return clientFetch<BatchPredictionsResponse>(url);
};
export const getBatchPredictionsWithStore = async (
period: number = 90,
): Promise<BatchPredictionsResponse> => {
const storeId = getStoreIdForUser();
return getBatchPredictions(period, storeId);
};