import { listCodes } from "@/lib/db/code-lists"; import { authErrorResponse, requireRole } from "@/lib/auth/session"; import { toCsv } from "@/lib/csv"; export async function GET() { try { await requireRole(["staff", "admin"]); const items = await listCodes("allergens"); const rows = [ ["code", "name", "name_en", "name_pl"], ...items.map((i) => [i.code, i.name, i.name_en ?? "", i.name_pl ?? ""]), ]; return new Response(toCsv(rows), { headers: { "Content-Type": "text/csv; charset=utf-8", "Content-Disposition": 'attachment; filename="allergene.csv"', }, }); } catch (err) { const res = authErrorResponse(err); if (res) return res; throw err; } }