27 lines
804 B
TypeScript
27 lines
804 B
TypeScript
import { connection } from "next/server";
|
|
import * as z from "zod";
|
|
|
|
import { updateVisitorPresence } from "@/lib/presence";
|
|
|
|
const inputSchema = z.strictObject({
|
|
tabId: z.string().uuid(),
|
|
guideId: z.string().uuid().nullable(),
|
|
active: z.boolean().default(true),
|
|
});
|
|
|
|
export async function POST(request: Request) {
|
|
await connection();
|
|
const parsed = inputSchema.safeParse(await request.json().catch(() => null));
|
|
if (!parsed.success) return Response.json({ error: "invalid-presence" }, { status: 400 });
|
|
try {
|
|
return Response.json(await updateVisitorPresence(parsed.data), {
|
|
headers: { "Cache-Control": "no-store" },
|
|
});
|
|
} catch {
|
|
return Response.json({ error: "presence-unavailable" }, {
|
|
status: 503,
|
|
headers: { "Cache-Control": "no-store" },
|
|
});
|
|
}
|
|
}
|