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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user