- Next.js 16 App Router site with the ANOUMA design system - Payload CMS (PostgreSQL) for offers, events, posts and page content - WebRTC video-call system with custom signaling server - SMTP email reminders and booking-request notifications - Customer accounts, calendar-based availability, and booking workflow
125 lines
3.7 KiB
TypeScript
125 lines
3.7 KiB
TypeScript
import { cache } from "react";
|
|
import { getCMS } from "@/lib/payload/getPayload";
|
|
import type { Event, Offer, Post } from "@/payload-types";
|
|
|
|
// Wrapped in React's `cache()` so multiple components reading the same data
|
|
// during one request (e.g. layout + page) only hit the database once.
|
|
//
|
|
// IMPORTANT: Payload's Local API defaults `overrideAccess` to `true`, which
|
|
// SKIPS each collection's `access.read` check entirely (see
|
|
// node_modules/payload/dist/collections/operations/find.js) — it does not
|
|
// automatically hide drafts. Every fetcher that feeds a *public* page must
|
|
// therefore pass `overrideAccess: false` so the collection's own
|
|
// `publishedOrAdmin` access rule actually filters out unpublished documents.
|
|
|
|
// ---- Angebote ---------------------------------------------------------
|
|
|
|
export const getOffers = cache(async (): Promise<Offer[]> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "offers",
|
|
sort: "order",
|
|
limit: 100,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs;
|
|
});
|
|
|
|
export const getOfferBySlug = cache(async (slug: string): Promise<Offer | null> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "offers",
|
|
where: { slug: { equals: slug } },
|
|
limit: 1,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs[0] ?? null;
|
|
});
|
|
|
|
// ---- Termine (Events) --------------------------------------------------
|
|
|
|
export const getUpcomingEvents = cache(async (limit = 6): Promise<Event[]> => {
|
|
const payload = await getCMS();
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
const result = await payload.find({
|
|
collection: "events",
|
|
where: { date: { greater_than_equal: today.toISOString() } },
|
|
sort: "date",
|
|
limit,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs;
|
|
});
|
|
|
|
export const getAllEvents = cache(async (): Promise<Event[]> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "events",
|
|
sort: "-date",
|
|
limit: 200,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs;
|
|
});
|
|
|
|
export const getEventBySlug = cache(async (slug: string): Promise<Event | null> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "events",
|
|
where: { slug: { equals: slug } },
|
|
limit: 1,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs[0] ?? null;
|
|
});
|
|
|
|
/**
|
|
* Unlike `getEventBySlug`, this intentionally does NOT filter by publish
|
|
* status. Confirmed private bookings create an unpublished/private linked
|
|
* Event (see collections/BookingRequests.ts) that must still be reachable
|
|
* for the one customer who received its join link + password — "unlisted",
|
|
* not "hidden". Only used by the join/beitreten flow, never for listings.
|
|
*/
|
|
export const getEventForJoin = cache(async (slug: string): Promise<Event | null> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "events",
|
|
where: { slug: { equals: slug } },
|
|
limit: 1,
|
|
depth: 1,
|
|
});
|
|
return result.docs[0] ?? null;
|
|
});
|
|
|
|
// ---- Aktuelles (Posts) --------------------------------------------------
|
|
|
|
export const getPosts = cache(async (limit = 50): Promise<Post[]> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "posts",
|
|
sort: "-publishDate",
|
|
limit,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs;
|
|
});
|
|
|
|
export const getPostBySlug = cache(async (slug: string): Promise<Post | null> => {
|
|
const payload = await getCMS();
|
|
const result = await payload.find({
|
|
collection: "posts",
|
|
where: { slug: { equals: slug } },
|
|
limit: 1,
|
|
depth: 1,
|
|
overrideAccess: false,
|
|
});
|
|
return result.docs[0] ?? null;
|
|
});
|