- Replace mock Nitro routes with server-side proxies to the Go API - /plan reads Go /api/staffing; local assumption edits are a labeled preview - /simulate reads base and scenario staffing from Go instead of local multipliers - Route train upload and scenario POST through Nitro with server-only credentials - Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only - Match Go's global-peak flat schedule and add a captured Go parity fixture - Run the web runtime as numeric UID/GID 10001:10001 - Add make check, Gitea CI workflow and a proxy smoke script
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { applyScenario, buildStaffing, planWeekStart } from '../../shared/staffing'
|
|
import { planDrivers } from '../../shared/insights'
|
|
import { SCENARIOS, STANDARDS } from '../../shared/types'
|
|
import type { Scenario, StaffingResponse, Standard } from '../../shared/types'
|
|
import { apiRequest, enumParam, isMockMode, sensorParam } from '../utils/api'
|
|
import { getMockForecast, mockContext, mockDemo } from '../utils/mock-data'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = getQuery(event)
|
|
const sensor = sensorParam(query.sensor)
|
|
const scenario = enumParam<Scenario>(query.scenario, SCENARIOS, 'scenario', 'base')
|
|
const standard = enumParam<Standard>(query.standard, STANDARDS, 'standard', 'standard')
|
|
|
|
if (isMockMode()) {
|
|
const forecast = getMockForecast(sensor)
|
|
if (!forecast) {
|
|
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
|
}
|
|
const weekStart = planWeekStart(mockDemo.now)
|
|
const build = buildStaffing({
|
|
sensor,
|
|
scenario,
|
|
standard,
|
|
points: applyScenario(forecast.points, scenario),
|
|
weekStart,
|
|
data_version: forecast.data_version,
|
|
model_version: forecast.model_version,
|
|
context_version: forecast.context_version,
|
|
})
|
|
build.response.why = planDrivers(build.response, mockContext, weekStart, scenario)
|
|
return build.response
|
|
}
|
|
|
|
// The Go API owns the plan. The browser never computes staffing in this path.
|
|
return apiRequest<StaffingResponse>('/api/staffing', {
|
|
query: { sensor, scenario, standard },
|
|
})
|
|
})
|