app: prayer requests' backend (APP-1.0-PLAN §4)

Private by default (the prayer team only) or shared with members after a
coordinator approves it, with the first name or "Anonymous"; fully anonymous
requests when the church allows them (off by default). Coordinators approve,
redact (the sender told what changed) or remove (with a reason); anyone on the
team can escalate to Pastoral care (email and WhatsApp at once, an Owner or
Church admin when nobody has the role): it leaves the shared list and the sender
sees nothing different. "I prayed" counts without who, "Answered!" updates,
private replies from the team, closing after 30 days (7-90) and deletion 12
months later (prayer-requests-tidy). Every list with a sender is access-logged;
messages never carry a request's text; nothing in the heartbeat. Export and
delete for a member's requests. Shared helpers: parse (http.ts), accessLog
(lib/accessLog.ts). Migration 20261203000000_prayer_requests (checked on
PostgreSQL 18: applies, no diff). 78 backend tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 10:56:53 +02:00
co-authored by Claude Opus 5.5
parent 1dd3aadb60
commit 6425a6a30d
16 changed files with 893 additions and 22 deletions
@@ -0,0 +1,82 @@
-- Church App 1.0.0: prayer requests (docs/APP-1.0-PLAN.md §4): requests with their moderation and
-- escalation, updates and replies, and "I prayed" counts.
-- CreateEnum
CREATE TYPE "RequestVisibility" AS ENUM ('team', 'members');
-- CreateEnum
CREATE TYPE "RequestModeration" AS ENUM ('none', 'pending', 'approved', 'removed');
-- CreateTable
CREATE TABLE "PrayerRequest" (
"id" TEXT NOT NULL,
"memberId" TEXT NOT NULL,
"text" TEXT NOT NULL,
"visibility" "RequestVisibility" NOT NULL DEFAULT 'team',
"showName" BOOLEAN NOT NULL DEFAULT false,
"anonymous" BOOLEAN NOT NULL DEFAULT false,
"moderation" "RequestModeration" NOT NULL DEFAULT 'none',
"redactedAt" TIMESTAMP(3),
"redactionNote" TEXT,
"removedReason" TEXT,
"moderatedById" TEXT,
"moderatedAt" TIMESTAMP(3),
"escalatedAt" TIMESTAMP(3),
"escalatedById" TEXT,
"escalationNote" TEXT,
"closesAt" TIMESTAMP(3) NOT NULL,
"closedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "PrayerRequest_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PrayerRequestUpdate" (
"id" TEXT NOT NULL,
"requestId" TEXT NOT NULL,
"author" TEXT NOT NULL,
"authorId" TEXT,
"text" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "PrayerRequestUpdate_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "RequestPrayer" (
"id" TEXT NOT NULL,
"requestId" TEXT NOT NULL,
"memberId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "RequestPrayer_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "PrayerRequest_moderation_createdAt_idx" ON "PrayerRequest"("moderation", "createdAt");
-- CreateIndex
CREATE INDEX "PrayerRequest_memberId_idx" ON "PrayerRequest"("memberId");
-- CreateIndex
CREATE INDEX "PrayerRequest_closedAt_idx" ON "PrayerRequest"("closedAt");
-- CreateIndex
CREATE INDEX "PrayerRequest_closesAt_idx" ON "PrayerRequest"("closesAt");
-- CreateIndex
CREATE INDEX "PrayerRequestUpdate_requestId_createdAt_idx" ON "PrayerRequestUpdate"("requestId", "createdAt");
-- CreateIndex
CREATE UNIQUE INDEX "RequestPrayer_requestId_memberId_key" ON "RequestPrayer"("requestId", "memberId");
-- AddForeignKey
ALTER TABLE "PrayerRequest" ADD CONSTRAINT "PrayerRequest_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PrayerRequestUpdate" ADD CONSTRAINT "PrayerRequestUpdate_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "PrayerRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "RequestPrayer" ADD CONSTRAINT "RequestPrayer_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "PrayerRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+82
View File
@@ -49,6 +49,7 @@ model Member {
prayerCommitments PrayerCommitment[]
testimonies Testimony[]
outboxMessages OutboxMessage[]
prayerRequests PrayerRequest[]
@@index([lastActiveAt])
}
@@ -284,3 +285,84 @@ model OutboxMessage {
@@index([sentAt, sendAfter])
}
// ── Prayer requests (§4) ─────────────────────────────────────────────────────────────────────
// Special personal information (POPIA s26): never in stats, the heartbeat, AI or an email's text.
// The rules (closing after 30 days, fully anonymous requests, emergency numbers) are in AppSetting
// `prayer_requests`. Every view of a request with its sender goes in the access log.
/// Who sees a request (P8): the prayer team only (the default), or members after approval.
enum RequestVisibility {
team
members
}
/// A shared request's moderation: waiting, approved (shown to members) or removed (with a reason).
/// Team-only requests are never moderated (`none`).
enum RequestModeration {
none
pending
approved
removed
}
model PrayerRequest {
id String @id @default(uuid())
memberId String
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade)
text String
visibility RequestVisibility @default(team)
/// For members: show the submitter's first name (else "Anonymous").
showName Boolean @default(false)
/// Fully anonymous (P9, when the church allows it): the prayer team doesn't see who sent it either.
anonymous Boolean @default(false)
moderation RequestModeration @default(none)
/// A coordinator edited out names or details; the submitter is told what changed.
redactedAt DateTime?
redactionNote String?
removedReason String?
moderatedById String?
moderatedAt DateTime?
/// Safeguarding (§4): sent to Pastoral care at once; it leaves the shared list; the submitter sees nothing different.
escalatedAt DateTime?
escalatedById String?
escalationNote String?
/// Closes itself then (30 days by default), unless closed before.
closesAt DateTime
closedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
updates PrayerRequestUpdate[]
prayers RequestPrayer[]
@@index([moderation, createdAt])
@@index([memberId])
@@index([closedAt])
@@index([closesAt])
}
/// "Answered!" from the submitter (shown with the request), or a private reply from the prayer team
/// (to the submitter alone).
model PrayerRequestUpdate {
id String @id @default(uuid())
requestId String
request PrayerRequest @relation(fields: [requestId], references: [id], onDelete: Cascade)
/// `submitter` or `team`.
author String
authorId String?
text String
createdAt DateTime @default(now())
@@index([requestId, createdAt])
}
/// "I prayed" on a shared request: the submitter sees how many, never who.
model RequestPrayer {
id String @id @default(uuid())
requestId String
request PrayerRequest @relation(fields: [requestId], references: [id], onDelete: Cascade)
memberId String
createdAt DateTime @default(now())
@@unique([requestId, memberId])
}