feat: build Onyx SSR shell and plan hero with mock data
This commit is contained in:
1 parent
84c20992f9
commit
2db494fb10
34 files changed
+3197
-2
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { applyScenario } from '../../shared/staffing'
|
||||
import { HORIZONS, SCENARIOS } from '../../shared/types'
|
||||
import type { Horizon, Scenario } from '../../shared/types'
|
||||
import { getMockForecast } from '../utils/mock-data'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const query = getQuery(event)
|
||||
const sensor = String(query.sensor ?? 'hn-stadtgalerie-01')
|
||||
const horizon = String(query.horizon ?? '7d') as Horizon
|
||||
const scenario = String(query.scenario ?? 'base') as Scenario
|
||||
const forecast = getMockForecast(sensor)
|
||||
|
||||
if (!forecast) {
|
||||
throw createError({ statusCode: 404, statusMessage: `Unknown sensor: ${sensor}` })
|
||||
}
|
||||
if (!HORIZONS.includes(horizon)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid horizon: ${horizon}` })
|
||||
}
|
||||
if (!SCENARIOS.includes(scenario)) {
|
||||
throw createError({ statusCode: 400, statusMessage: `Invalid scenario: ${scenario}` })
|
||||
}
|
||||
|
||||
const points = applyScenario(forecast.points, scenario)
|
||||
const limit = horizon === '15m' ? 1 : horizon === '1h' ? 4 : horizon === '48h' ? 48 : points.length
|
||||
|
||||
return {
|
||||
...forecast,
|
||||
horizon,
|
||||
scenario,
|
||||
points: points.slice(0, limit),
|
||||
// The mock is computed locally; it is not a cached fallback from the Go API.
|
||||
cached: false,
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user