ci / check (push) Successful in 55s
- add /cool, /cool?vote=1, /cool/stage and /cool/city on the existing Nuxt/Onyx stack - wire real route/shade metrics and OSM geometry from the route bundle; city-gap data for the city view - show shade % and direct-sun minutes together; recommend Accessible for Ruth with the 15% ramp trade-off - add in-memory time/scene/round state and one anonymous vote per session, polled every 2 s - keep the retail module linked but out of the Cool City story
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { isCoolRouteId, isCoolRound, isCoolScene, isCoolTime } from '../../../shared/cool'
|
|
import { updateCoolState } from '../../utils/cool-votes'
|
|
|
|
interface StateBody {
|
|
round?: unknown
|
|
time?: unknown
|
|
selectedRoute?: unknown
|
|
scene?: unknown
|
|
voteOpen?: unknown
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
setHeader(event, 'cache-control', 'no-store')
|
|
const body = await readBody<StateBody>(event)
|
|
const round = body?.round ?? 'preselection'
|
|
if (!isCoolRound(round)) {
|
|
throw createError({ statusCode: 400, statusMessage: 'Invalid round. Expected preselection | final.' })
|
|
}
|
|
if (body.time !== undefined && !isCoolTime(body.time)) {
|
|
throw createError({ statusCode: 400, statusMessage: 'Invalid time. Expected 10:00 | 12:00 | 14:00 | 16:00.' })
|
|
}
|
|
if (body.selectedRoute !== undefined && !isCoolRouteId(body.selectedRoute)) {
|
|
throw createError({ statusCode: 400, statusMessage: 'Invalid route.' })
|
|
}
|
|
if (body.scene !== undefined && !isCoolScene(body.scene)) {
|
|
throw createError({ statusCode: 400, statusMessage: 'Invalid scene.' })
|
|
}
|
|
if (body.voteOpen !== undefined && typeof body.voteOpen !== 'boolean') {
|
|
throw createError({ statusCode: 400, statusMessage: 'voteOpen must be a boolean.' })
|
|
}
|
|
|
|
return updateCoolState(round, {
|
|
...(isCoolTime(body.time) ? { time: body.time } : {}),
|
|
...(isCoolRouteId(body.selectedRoute) ? { selectedRoute: body.selectedRoute } : {}),
|
|
...(isCoolScene(body.scene) ? { scene: body.scene } : {}),
|
|
...(typeof body.voteOpen === 'boolean' ? { voteOpen: body.voteOpen } : {}),
|
|
})
|
|
})
|