feature: pope prayer intentions
This commit is contained in:
parent
cb5fb6dc7a
commit
07e6b35916
8 changed files with 6496 additions and 2 deletions
151
src/app/gebetsanliegen-des-papstes/[year]/[month]/page.tsx
Normal file
151
src/app/gebetsanliegen-des-papstes/[year]/[month]/page.tsx
Normal file
|
|
@ -0,0 +1,151 @@
|
||||||
|
import { Section } from '@/components/Section/Section'
|
||||||
|
import { fetchPopePrayerIntentions } from '@/fetch/popePrayerIntentions'
|
||||||
|
import { Container } from '@/components/Container/Container'
|
||||||
|
import { Title } from '@/components/Title/Title'
|
||||||
|
import { P } from '@/components/Text/Paragraph'
|
||||||
|
import { PageHeader } from '@/compositions/PageHeader/PageHeader'
|
||||||
|
import { NextPrevButtons } from '@/components/NextPrevButtons/NextPrevButtons'
|
||||||
|
|
||||||
|
const months: Record<string, string> = {
|
||||||
|
"01": "Januar",
|
||||||
|
"02": "Februar",
|
||||||
|
"03": "März",
|
||||||
|
"04": "April",
|
||||||
|
"05": "Mai",
|
||||||
|
"06": "June",
|
||||||
|
"07": "July",
|
||||||
|
"08": "August",
|
||||||
|
"09": "September",
|
||||||
|
"10": "Oktober",
|
||||||
|
"11": "November",
|
||||||
|
"12": "Dezember",
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMonthAsString = (month: string): string => {
|
||||||
|
if (months.hasOwnProperty(month)) {
|
||||||
|
return months[month];
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get next month
|
||||||
|
* eg: "12" => "01"
|
||||||
|
*
|
||||||
|
* @param month
|
||||||
|
*/
|
||||||
|
function nextMonth(month: string) {
|
||||||
|
let monthNumber = parseInt(month, 10);
|
||||||
|
monthNumber++;
|
||||||
|
|
||||||
|
if (monthNumber > 12) {
|
||||||
|
monthNumber = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return monthNumber.toString().padStart(2, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get previous month
|
||||||
|
* eg: "03" => "02"
|
||||||
|
*
|
||||||
|
* @param month
|
||||||
|
*/
|
||||||
|
function prevMonth(month: string) {
|
||||||
|
let monthNumber = parseInt(month, 10);
|
||||||
|
monthNumber--;
|
||||||
|
|
||||||
|
if (monthNumber == 0) {
|
||||||
|
monthNumber = 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
return monthNumber.toString().padStart(2, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get next url
|
||||||
|
*
|
||||||
|
* @param year
|
||||||
|
* @param month
|
||||||
|
*/
|
||||||
|
function nextUrl(year: number, month: string) {
|
||||||
|
const next = nextMonth(month);
|
||||||
|
if (next == "01") {
|
||||||
|
year++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `/gebetsanliegen-des-papstes/${year}/${next}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get previous url
|
||||||
|
*
|
||||||
|
* @param year
|
||||||
|
* @param month
|
||||||
|
*/
|
||||||
|
function prevUrl(year: number, month: string) {
|
||||||
|
const prev = prevMonth(month);
|
||||||
|
if (prev == "12") {
|
||||||
|
year--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `/gebetsanliegen-des-papstes/${year}/${prev}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function PrayerIntentionPage({ params }: { params: Promise<{year: string, month: string}>}) {
|
||||||
|
const {year, month} = await params;
|
||||||
|
const yearInt = parseInt(year, 10);
|
||||||
|
let prayer = await fetchPopePrayerIntentions(yearInt, month)
|
||||||
|
const monthString = getMonthAsString(month)
|
||||||
|
|
||||||
|
if(!prayer) {
|
||||||
|
prayer = {
|
||||||
|
id: "dummy",
|
||||||
|
createdAt: "",
|
||||||
|
updatedAt: "",
|
||||||
|
month: "01",
|
||||||
|
year: 2025,
|
||||||
|
title: "Nicht gefunden",
|
||||||
|
prayer: "Gebetsanliegen nicht gefunden"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<PageHeader
|
||||||
|
title={"Gebetsanliegen des Papstes"}
|
||||||
|
description={"Der Papst lädt uns ein, uns mit ihm im Gebet zu verbinden und gemeinsam die Welt vor Gott zu tragen."}
|
||||||
|
/>
|
||||||
|
<Section padding={"small"}>
|
||||||
|
<Container>
|
||||||
|
<Title
|
||||||
|
color={"contrast"}
|
||||||
|
title={`${monthString} ${year}: ${prayer.title}`}
|
||||||
|
size={"sm"}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<P width={"3/4"}>
|
||||||
|
{ prayer.prayer}
|
||||||
|
</P>
|
||||||
|
</Container>
|
||||||
|
</Section>
|
||||||
|
<Section>
|
||||||
|
</Section>
|
||||||
|
<Section padding={"small"}>
|
||||||
|
<NextPrevButtons
|
||||||
|
prev={{
|
||||||
|
href: prevUrl(yearInt, month),
|
||||||
|
text: getMonthAsString(prevMonth(month))
|
||||||
|
}}
|
||||||
|
next={{
|
||||||
|
href: nextUrl(yearInt, month),
|
||||||
|
text: getMonthAsString(nextMonth(month))
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Section>
|
||||||
|
</>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
110
src/collections/PopesPrayerIntentions.ts
Normal file
110
src/collections/PopesPrayerIntentions.ts
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
import { CollectionConfig } from 'payload'
|
||||||
|
import { isAdminOrEmployee } from '@/collections/access/admin'
|
||||||
|
|
||||||
|
export const PopesPrayerIntentions: CollectionConfig = {
|
||||||
|
slug: 'popePrayerIntentions',
|
||||||
|
labels: {
|
||||||
|
singular: {
|
||||||
|
de: 'Gebetsanliegen des Papstes'
|
||||||
|
},
|
||||||
|
plural: {
|
||||||
|
de: 'Gebetsanliegen des Papstes'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'year',
|
||||||
|
type: 'number',
|
||||||
|
label: {
|
||||||
|
de: "Jahr"
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
defaultValue: new Date().getFullYear(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'month',
|
||||||
|
type: 'select',
|
||||||
|
label: {
|
||||||
|
de: 'Monat'
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Januar',
|
||||||
|
value: '01',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Februar',
|
||||||
|
value: '02',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'März',
|
||||||
|
value: '03',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'April',
|
||||||
|
value: '04',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Mai',
|
||||||
|
value: '05',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Juni',
|
||||||
|
value: '06'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Juli',
|
||||||
|
value: '07',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'August',
|
||||||
|
value: '08',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'September',
|
||||||
|
value: '09',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Oktober',
|
||||||
|
value: '10',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'November',
|
||||||
|
value: '11',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Dezember',
|
||||||
|
value: '12'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
required: true,
|
||||||
|
defaultValue: '01'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
name: 'title',
|
||||||
|
label: {
|
||||||
|
de: "Titel"
|
||||||
|
},
|
||||||
|
defaultValue: "Für ",
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'prayer',
|
||||||
|
label: {
|
||||||
|
de: "Gebet"
|
||||||
|
},
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
admin: {
|
||||||
|
useAsTitle: 'title',
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
read: () => true,
|
||||||
|
create: isAdminOrEmployee(),
|
||||||
|
update: isAdminOrEmployee(),
|
||||||
|
delete: isAdminOrEmployee(),
|
||||||
|
},
|
||||||
|
}
|
||||||
36
src/fetch/popePrayerIntentions.ts
Normal file
36
src/fetch/popePrayerIntentions.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { stringify } from 'qs-esm'
|
||||||
|
import { PopePrayerIntention } from '@/payload-types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch pope prayer intentions
|
||||||
|
*
|
||||||
|
* @param year
|
||||||
|
* @param month - in the form of '01' for january, '02' for february ...
|
||||||
|
*/
|
||||||
|
export const fetchPopePrayerIntentions = async (year: number, month: string): Promise<PopePrayerIntention | undefined> => {
|
||||||
|
const query: any = {
|
||||||
|
and: [
|
||||||
|
{
|
||||||
|
month: {
|
||||||
|
equals: month,
|
||||||
|
},
|
||||||
|
year: {
|
||||||
|
equals: year
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const stringifiedQuery = stringify(
|
||||||
|
{
|
||||||
|
where: query,
|
||||||
|
limit: 1
|
||||||
|
},
|
||||||
|
{ addQueryPrefix: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
const response = await fetch(`http://localhost:3000/api/popePrayerIntentions${stringifiedQuery}`)
|
||||||
|
if (!response.ok) return undefined
|
||||||
|
let data = await response.json()
|
||||||
|
return data.docs[0]
|
||||||
|
}
|
||||||
6121
src/migrations/20250128_100809_pope_prayer_intentions.json
Normal file
6121
src/migrations/20250128_100809_pope_prayer_intentions.json
Normal file
File diff suppressed because it is too large
Load diff
37
src/migrations/20250128_100809_pope_prayer_intentions.ts
Normal file
37
src/migrations/20250128_100809_pope_prayer_intentions.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||||
|
|
||||||
|
export async function up({ payload, req }: MigrateUpArgs): Promise<void> {
|
||||||
|
await payload.db.drizzle.execute(sql`
|
||||||
|
CREATE TYPE "public"."enum_pope_prayer_intentions_month" AS ENUM('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
|
||||||
|
CREATE TABLE IF NOT EXISTS "pope_prayer_intentions" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"year" numeric DEFAULT 2025 NOT NULL,
|
||||||
|
"month" "enum_pope_prayer_intentions_month" DEFAULT '01' NOT NULL,
|
||||||
|
"title" varchar DEFAULT 'Für ' NOT NULL,
|
||||||
|
"prayer" varchar NOT NULL,
|
||||||
|
"updated_at" timestamp(3) with time zone DEFAULT now() NOT NULL,
|
||||||
|
"created_at" timestamp(3) with time zone DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" ADD COLUMN "pope_prayer_intentions_id" uuid;
|
||||||
|
CREATE INDEX IF NOT EXISTS "pope_prayer_intentions_updated_at_idx" ON "pope_prayer_intentions" USING btree ("updated_at");
|
||||||
|
CREATE INDEX IF NOT EXISTS "pope_prayer_intentions_created_at_idx" ON "pope_prayer_intentions" USING btree ("created_at");
|
||||||
|
DO $$ BEGIN
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" ADD CONSTRAINT "payload_locked_documents_rels_pope_prayer_intentions_fk" FOREIGN KEY ("pope_prayer_intentions_id") REFERENCES "public"."pope_prayer_intentions"("id") ON DELETE cascade ON UPDATE no action;
|
||||||
|
EXCEPTION
|
||||||
|
WHEN duplicate_object THEN null;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "payload_locked_documents_rels_pope_prayer_intentions_id_idx" ON "payload_locked_documents_rels" USING btree ("pope_prayer_intentions_id");`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down({ payload, req }: MigrateDownArgs): Promise<void> {
|
||||||
|
await payload.db.drizzle.execute(sql`
|
||||||
|
ALTER TABLE "pope_prayer_intentions" DISABLE ROW LEVEL SECURITY;
|
||||||
|
DROP TABLE "pope_prayer_intentions" CASCADE;
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" DROP CONSTRAINT "payload_locked_documents_rels_pope_prayer_intentions_fk";
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS "payload_locked_documents_rels_pope_prayer_intentions_id_idx";
|
||||||
|
ALTER TABLE "payload_locked_documents_rels" DROP COLUMN IF EXISTS "pope_prayer_intentions_id";
|
||||||
|
DROP TYPE "public"."enum_pope_prayer_intentions_month";`)
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import * as migration_20241205_121237 from './20241205_121237';
|
import * as migration_20241205_121237 from './20241205_121237';
|
||||||
import * as migration_20241217_135114_contact_person_photo from './20241217_135114_contact_person_photo';
|
import * as migration_20241217_135114_contact_person_photo from './20241217_135114_contact_person_photo';
|
||||||
|
import * as migration_20250128_100809_pope_prayer_intentions from './20250128_100809_pope_prayer_intentions';
|
||||||
|
|
||||||
export const migrations = [
|
export const migrations = [
|
||||||
{
|
{
|
||||||
|
|
@ -10,6 +11,11 @@ export const migrations = [
|
||||||
{
|
{
|
||||||
up: migration_20241217_135114_contact_person_photo.up,
|
up: migration_20241217_135114_contact_person_photo.up,
|
||||||
down: migration_20241217_135114_contact_person_photo.down,
|
down: migration_20241217_135114_contact_person_photo.down,
|
||||||
name: '20241217_135114_contact_person_photo'
|
name: '20241217_135114_contact_person_photo',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
up: migration_20250128_100809_pope_prayer_intentions.up,
|
||||||
|
down: migration_20250128_100809_pope_prayer_intentions.down,
|
||||||
|
name: '20250128_100809_pope_prayer_intentions'
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ export interface Config {
|
||||||
parish: Parish;
|
parish: Parish;
|
||||||
church: Church;
|
church: Church;
|
||||||
worship: Worship;
|
worship: Worship;
|
||||||
|
popePrayerIntentions: PopePrayerIntention;
|
||||||
announcement: Announcement;
|
announcement: Announcement;
|
||||||
blog: Blog;
|
blog: Blog;
|
||||||
highlight: Highlight;
|
highlight: Highlight;
|
||||||
|
|
@ -36,6 +37,7 @@ export interface Config {
|
||||||
parish: ParishSelect<false> | ParishSelect<true>;
|
parish: ParishSelect<false> | ParishSelect<true>;
|
||||||
church: ChurchSelect<false> | ChurchSelect<true>;
|
church: ChurchSelect<false> | ChurchSelect<true>;
|
||||||
worship: WorshipSelect<false> | WorshipSelect<true>;
|
worship: WorshipSelect<false> | WorshipSelect<true>;
|
||||||
|
popePrayerIntentions: PopePrayerIntentionsSelect<false> | PopePrayerIntentionsSelect<true>;
|
||||||
announcement: AnnouncementSelect<false> | AnnouncementSelect<true>;
|
announcement: AnnouncementSelect<false> | AnnouncementSelect<true>;
|
||||||
blog: BlogSelect<false> | BlogSelect<true>;
|
blog: BlogSelect<false> | BlogSelect<true>;
|
||||||
highlight: HighlightSelect<false> | HighlightSelect<true>;
|
highlight: HighlightSelect<false> | HighlightSelect<true>;
|
||||||
|
|
@ -212,6 +214,19 @@ export interface Worship {
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "popePrayerIntentions".
|
||||||
|
*/
|
||||||
|
export interface PopePrayerIntention {
|
||||||
|
id: string;
|
||||||
|
year: number;
|
||||||
|
month: '01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09' | '10' | '11' | '12';
|
||||||
|
title: string;
|
||||||
|
prayer: string;
|
||||||
|
updatedAt: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "announcement".
|
* via the `definition` "announcement".
|
||||||
|
|
@ -559,6 +574,10 @@ export interface PayloadLockedDocument {
|
||||||
relationTo: 'worship';
|
relationTo: 'worship';
|
||||||
value: string | Worship;
|
value: string | Worship;
|
||||||
} | null)
|
} | null)
|
||||||
|
| ({
|
||||||
|
relationTo: 'popePrayerIntentions';
|
||||||
|
value: string | PopePrayerIntention;
|
||||||
|
} | null)
|
||||||
| ({
|
| ({
|
||||||
relationTo: 'announcement';
|
relationTo: 'announcement';
|
||||||
value: string | Announcement;
|
value: string | Announcement;
|
||||||
|
|
@ -708,6 +727,18 @@ export interface WorshipSelect<T extends boolean = true> {
|
||||||
updatedAt?: T;
|
updatedAt?: T;
|
||||||
createdAt?: T;
|
createdAt?: T;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
|
* via the `definition` "popePrayerIntentions_select".
|
||||||
|
*/
|
||||||
|
export interface PopePrayerIntentionsSelect<T extends boolean = true> {
|
||||||
|
year?: T;
|
||||||
|
month?: T;
|
||||||
|
title?: T;
|
||||||
|
prayer?: T;
|
||||||
|
updatedAt?: T;
|
||||||
|
createdAt?: T;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `Config`'s JSON-Schema
|
* This interface was referenced by `Config`'s JSON-Schema
|
||||||
* via the `definition` "announcement_select".
|
* via the `definition` "announcement_select".
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import { Locations } from '@/collections/Locations'
|
||||||
import { ContactPerson } from '@/collections/ContactPerson'
|
import { ContactPerson } from '@/collections/ContactPerson'
|
||||||
import { postgresAdapter } from '@payloadcms/db-postgres'
|
import { postgresAdapter } from '@payloadcms/db-postgres'
|
||||||
import { gcsStorage } from '@payloadcms/storage-gcs'
|
import { gcsStorage } from '@payloadcms/storage-gcs'
|
||||||
|
import { PopesPrayerIntentions } from '@/collections/PopesPrayerIntentions'
|
||||||
|
|
||||||
const filename = fileURLToPath(import.meta.url)
|
const filename = fileURLToPath(import.meta.url)
|
||||||
const dirname = path.dirname(filename)
|
const dirname = path.dirname(filename)
|
||||||
|
|
@ -48,6 +49,7 @@ export default buildConfig({
|
||||||
Parish,
|
Parish,
|
||||||
Churches,
|
Churches,
|
||||||
Worship,
|
Worship,
|
||||||
|
PopesPrayerIntentions,
|
||||||
Announcements,
|
Announcements,
|
||||||
Blog,
|
Blog,
|
||||||
Highlight,
|
Highlight,
|
||||||
|
|
@ -87,7 +89,7 @@ export default buildConfig({
|
||||||
},
|
},
|
||||||
db: postgresAdapter({
|
db: postgresAdapter({
|
||||||
idType: "uuid",
|
idType: "uuid",
|
||||||
push: false,
|
push: true,
|
||||||
pool: {
|
pool: {
|
||||||
connectionString: process.env.DATABASE_URI,
|
connectionString: process.env.DATABASE_URI,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue