35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
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,
|
|
}
|
|
})
|