Files
lunch/lib/kitchen.ts
T
kai eb157ab55b
release / which version (push) Successful in 3s
release / olares chart · sanity (push) Successful in 4s
release / app (push) Successful in 1m8s
release / tag and release (push) Successful in 2s
26.11.28: Präsentationsmodus und Küchendisplay (#29)
2026-11-07 10:02:25 +00:00

36 lines
1.8 KiB
TypeScript

import "server-only";
import type { PoolClient } from "pg";
import { getSession } from "./auth/session";
import { currentKitchenDisplay } from "./auth/kids";
import { listDishes, type DishSummary } from "./dishes";
import { currentRound } from "./rounds";
// Küchendisplay und Präsentation (26.11.28): wer darf ansehen, und was steht an.
/** Wer ein Rezept präsentieren darf: eine Sitzung (nicht Gast) oder ein Küchendisplay. */
export async function presenter(): Promise<{ householdId: string; display: boolean } | null> {
const session = await getSession();
if (session) return session.role === "guest" ? null : { householdId: session.householdId, display: false };
const device = await currentKitchenDisplay();
return device ? { householdId: device.householdId, display: true } : null;
}
export type PlannedDish = { slotId: string; dishId: string; title: string; photo: string | null; portions: number; cookName: string | null };
/** Die noch nicht gekochten Gerichte der laufenden Runde, in Reihenfolge; das erste ist „Heute“. */
export async function upcoming(client: PoolClient): Promise<PlannedDish[]> {
const round = await currentRound(client);
if (!round || round.status === "open") return [];
const { rows } = await client.query(
`select s.id as "slotId", d.id as "dishId", d.title, d.photo_path as photo, s.portions, m.display_name as "cookName"
from slots s join dishes d on d.id = s.dish_id left join members m on m.id = s.cook_member_id
where s.round_id = $1 and s.cooked_at is null order by s.position`,
[round.id],
);
return rows;
}
export async function kitchenOverview(client: PoolClient): Promise<{ next: PlannedDish[]; dishes: DishSummary[] }> {
return { next: await upcoming(client), dishes: await listDishes(client) };
}