feat: wire Nitro API to Go, real staffing plan and train proxy
- 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
This commit is contained in:
1 parent
e8d141ca43
commit
b33e6ff001
33 files changed
+1147
-317
No files matched your search
+27
-26
@@ -1,37 +1,38 @@
|
||||
import { applyScenario, buildStaffing, planWeekStart } from '../../shared/staffing'
|
||||
import { planDrivers } from '../../shared/insights'
|
||||
import { SCENARIOS, STANDARDS } from '../../shared/types'
|
||||
import type { Scenario, Standard } 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((event) => {
|
||||
export default defineEventHandler(async (event) => {
|
||||
const query = getQuery(event)
|
||||
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
|
||||
const scenario = String(query.scenario ?? 'base') as Scenario
|
||||
const standard = String(query.standard ?? 'standard') as Standard
|
||||
const forecast = getMockForecast(sensor)
|
||||
const sensor = sensorParam(query.sensor)
|
||||
const scenario = enumParam<Scenario>(query.scenario, SCENARIOS, 'scenario', 'base')
|
||||
const standard = enumParam<Standard>(query.standard, STANDARDS, 'standard', 'standard')
|
||||
|
||||
if (!forecast) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
||||
}
|
||||
if (!SCENARIOS.includes(scenario)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid scenario: ${scenario}` })
|
||||
}
|
||||
if (!STANDARDS.includes(standard)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid 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
|
||||
}
|
||||
|
||||
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,
|
||||
// The Go API owns the plan. The browser never computes staffing in this path.
|
||||
return apiRequest<StaffingResponse>('/api/staffing', {
|
||||
query: { sensor, scenario, standard },
|
||||
})
|
||||
build.response.why = planDrivers(build.response, mockContext, weekStart, scenario)
|
||||
return build.response
|
||||
})
|
||||
Reference in new issue
Block a user