Files
lunch/lib/dedication.ts
T
kai 4f4983f70e
release / which version (push) Successful in 3s
release / olares chart · sanity (push) Successful in 3s
release / app (push) Successful in 1m6s
release / tag and release (push) Successful in 2s
26.11.35: foodplanhero – Plan. Cook. Smile. Für Maike (#36)
2026-11-07 12:29:55 +00:00

33 lines
1.4 KiB
TypeScript

import "server-only";
import type { PoolClient } from "pg";
import { withAuth } from "./db";
// Widmung (26.11.35): „foodplanhero by Maike“. Name, Foto und Text je Haushalt;
// das Foto liegt wie die Gerichtsfotos unter /app/data/fotos/<haushalt>/.
export type Dedication = { name: string | null; text: string | null; photo: string | null };
export async function getDedication(client: PoolClient): Promise<Dedication> {
const { rows } = await client.query(
`select dedication_name as name, dedication_text as text, dedication_photo as photo from households limit 1`,
);
return rows[0] ?? { name: null, text: null, photo: null };
}
/**
* Vor der Anmeldung (Anmelden, Startbild) kennt die App keinen Haushalt. Auf einer
* Box gibt es in aller Regel genau einen; gezeigt wird der älteste.
*/
export async function publicDedication(): Promise<(Dedication & { householdId: string }) | null> {
return withAuth(async (c) => {
const { rows } = await c.query(
`select id as "householdId", dedication_name as name, dedication_text as text, dedication_photo as photo
from households order by created_at limit 1`,
);
return rows[0] ?? null;
});
}
/** Version des Fotos für die Adresse (?v=…), aus der Prüfsumme im Dateinamen. */
export const photoVersion = (photo: string | null) => photo?.split("-").at(-1)?.replace(".webp", "") ?? "";