28 lines
865 B
TypeScript
28 lines
865 B
TypeScript
import { getGameDb } from '@/lib/db/client'
|
|
import { JumpError, jumpToSystem } from '@/lib/game/save'
|
|
|
|
// Jump to an adjacent solar system. Body: { "systemId": number }. Returns the fresh world state.
|
|
export async function POST(req: Request) {
|
|
let body: unknown
|
|
try {
|
|
body = await req.json()
|
|
} catch {
|
|
return Response.json({ error: 'Invalid JSON body' }, { status: 400 })
|
|
}
|
|
|
|
const systemId = (body as { systemId?: unknown }).systemId
|
|
if (typeof systemId !== 'number' || !Number.isInteger(systemId)) {
|
|
return Response.json({ error: 'systemId must be an integer' }, { status: 400 })
|
|
}
|
|
|
|
try {
|
|
const db = await getGameDb()
|
|
return Response.json(await jumpToSystem(db, systemId))
|
|
} catch (err) {
|
|
if (err instanceof JumpError) {
|
|
return Response.json({ error: err.message }, { status: err.status })
|
|
}
|
|
throw err
|
|
}
|
|
}
|