import { api } from './client'; import type { FlightParameters, RawPrediction } from '$domain'; export function buildLaunchDateTime(date: string, time: string): string { const fullTime = time.split(':').length === 2 ? `${time}:00` : time; return new Date(`${date}T${fullTime}Z`).toISOString(); } export interface PredictionResponse { result: RawPrediction; } export const predictionsApi = { run: (params: FlightParameters, launchDateTime: string) => { // `dataset` carries only what the operator actually chose. It used to fall // back to a client-side guess at which GFS run the server holds — and the // guess had degenerated into a hardcoded 2025-04-06, over a year stale. The // client cannot know which runs are stored; the predictor refuses one it // does not have, so an unset value must stay unset and let the server pick. const { dataset, ...rest } = params; const payload = { ...rest, ...(dataset ? { dataset } : {}), launch_datetime: launchDateTime, } as FlightParameters & { launch_datetime: string }; if (payload.start_point === -1) delete payload.start_point; return api.post('/predictions/', payload); }, };