33 lines
1.4 KiB
TypeScript
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", "") ?? "";
|