2026-08-25 07:51:38 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
import { listPlaySessions, startPlaySession } from "@/lib/db/queries/play-sessions";
|
2026-08-26 08:45:15 +02:00
|
|
|
import { withRouteLogging } from "@/lib/api/with-route-logging";
|
2026-08-25 07:51:38 +02:00
|
|
|
|
|
|
|
|
const deviceInputSchema = z.object({
|
|
|
|
|
slotLabel: z.string().min(1),
|
|
|
|
|
bleName: z.string().min(1),
|
|
|
|
|
deviceClass: z.string().nullish(),
|
|
|
|
|
capabilities: z.object({ outputs: z.array(z.string()), featureCount: z.number() }).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const bodySchema = z.object({
|
|
|
|
|
kind: z.enum(["live", "replay"]),
|
|
|
|
|
replayedRecordingId: z.number().int().positive().optional(),
|
|
|
|
|
name: z.string().min(1).optional(),
|
|
|
|
|
devices: z.array(deviceInputSchema).min(1),
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const GET = withRouteLogging("play-sessions.list", async () => {
|
2026-08-25 07:51:38 +02:00
|
|
|
const rows = await listPlaySessions();
|
|
|
|
|
return NextResponse.json({ playSessions: rows });
|
2026-08-26 08:45:15 +02:00
|
|
|
});
|
2026-08-25 07:51:38 +02:00
|
|
|
|
2026-08-26 08:45:15 +02:00
|
|
|
export const POST = withRouteLogging("play-sessions.start", async (req: Request) => {
|
2026-08-25 07:51:38 +02:00
|
|
|
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
|
|
|
|
|
if (!parsed.success) {
|
|
|
|
|
return NextResponse.json({ error: parsed.error.message }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
const result = await startPlaySession(parsed.data);
|
|
|
|
|
return NextResponse.json(result, { status: 201 });
|
2026-08-26 08:45:15 +02:00
|
|
|
});
|