import { NextResponse } from "next/server"; import { listClosedDays, setClosedDay } from "@/lib/db/closed-days"; import { authErrorResponse, requireRole } from "@/lib/auth/session"; import { isSameOrigin } from "@/lib/origin"; export async function GET(request: Request) { const { searchParams } = new URL(request.url); const from = searchParams.get("from"); const to = searchParams.get("to"); if (!from || !to) { return NextResponse.json({ error: "invalid_input" }, { status: 400 }); } return NextResponse.json(await listClosedDays(from, to)); } export async function POST(request: Request) { if (!isSameOrigin(request)) { return NextResponse.json({ error: "Nicht erlaubt." }, { status: 403 }); } try { await requireRole(["staff", "admin"]); const body = (await request.json()) as { closed_date: string; reason: string | null; translations?: Record; }; const closedDay = await setClosedDay(body.closed_date, body.reason, body.translations); return NextResponse.json(closedDay, { status: 201 }); } catch (err) { const res = authErrorResponse(err); if (res) return res; throw err; } }