Files
Speisekarte/lib/db/menu-entries.ts
T
florian.wilde cd8b0fab9f feat: Speiseplan-Inhalte variabel mehrsprachig (Teil 2)
Gerichtnamen, Essenszeiten und Allergen-/Zusatzstoff-Bezeichnungen sind
jetzt genauso dynamisch mehrsprachig wie die Bedienoberfläche aus
v1.10.0, statt fest auf Englisch/Polnisch begrenzt zu sein. Neue
Übersetzungstabellen ersetzen die alten name_en/name_pl-Spalten,
DeepL-Auto-Übersetzung und CSV-Import/-Export unterstützen jetzt
beliebig viele aktive Sprachen.
2026-07-20 11:10:06 +02:00

50 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import "server-only";
import { query } from "@/lib/db";
import { loadTranslationsFor } from "./translations";
import type { MenuEntry } from "@/lib/types";
interface MenuEntryRow {
id: string;
menu_date: string;
section_key: string;
position: number;
dish_id: string;
name: string;
price: string;
allergens: string[];
additives: string[];
}
/** Wochenplan-Einträge inkl. zugehörigem Gericht für den Zeitraum laden –
* gemeinsam von der öffentlichen Speisekarte (Server Component) und
* /api/menu-entries genutzt, damit der JOIN nur einmal gepflegt wird. */
export async function loadMenuEntries(fromISO: string, toISO: string): Promise<MenuEntry[]> {
const rows = await query<MenuEntryRow>(
`select me.id, me.menu_date, me.section_key, me.position,
d.id as dish_id, d.name, d.price, d.allergens, d.additives
from menu_entries me
join dishes d on d.id = me.dish_id
where me.menu_date between $1 and $2
order by me.position, me.created_at`,
[fromISO, toISO]
);
const dishIds = [...new Set(rows.map((r) => r.dish_id))];
const translations = await loadTranslationsFor("dish_translations", dishIds);
return rows.map((r) => ({
id: r.id,
menu_date: r.menu_date,
section_key: r.section_key,
position: r.position,
dish: {
id: r.dish_id,
name: r.name,
translations: translations.get(r.dish_id) ?? {},
price: Number(r.price),
allergens: r.allergens,
additives: r.additives,
},
}));
}