CSV-Import/-Export (Gerichte, Allergene, Zusatzstoffe): neue Export-/ Import-Routen unter app/api/*/export und */import, hand-geschriebener CSV-Parser/-Serializer (lib/csv.ts, keine neue Abhängigkeit), Upsert über Kürzel (Allergene/Zusatzstoffe) bzw. exakten Namen (Gerichte, mit Ambiguitäts-Check bei Namensdopplung). UI-Buttons in DishManager und CodeListManager. RSS-Feed: <content:encoded> zusätzlich zu <description> ausgeben, da mehrere Feed-Reader description als kürzbare Vorschau behandeln und dadurch bei mehreren Essenszeiten pro Tag nur die erste zeigten. Version 1.7.0. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
25 lines
736 B
TypeScript
25 lines
736 B
TypeScript
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("additives");
|
|
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="zusatzstoffe.csv"',
|
|
},
|
|
});
|
|
} catch (err) {
|
|
const res = authErrorResponse(err);
|
|
if (res) return res;
|
|
throw err;
|
|
}
|
|
}
|