app: email and WhatsApp's backend (APP-1.0-PLAN §8)

The church's one set of settings from Accounts (messaging.get; the SMTP
password and WAWP token sealed with the link's secret, kept encrypted in
AppSetting messaging_settings), fetched when the App links to Accounts, on
Accounts' signed messaging.changed, once a day and on the admin's Fetch again.

messages-send (every minute): the outbox by email (nodemailer) and WhatsApp
(WAWP), STOP checked before every WhatsApp (the member and anyone with the
same number), email instead for what a member asked for (never
announcements), retries after 2, 4, 8 and 16 minutes, a reminder never after
its slot started, nothing more than 3 days late. announcement-sends and
devotional-sends queue "Also send it" at the publish time and today's
devotional at each member's time. Members' choices (NotificationSettings),
news consent kept from Accounts, MessageCount for the heartbeat's messages,
the admin's Email and WhatsApp API with Send a test.

Migration messaging (checked on PostgreSQL 18). 110 backend tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 14:29:13 +02:00
co-authored by Claude Opus 5.5
parent 7ff318a682
commit 8bfd0b767d
23 changed files with 1503 additions and 34 deletions
@@ -0,0 +1,45 @@
-- Church App 1.0.0: email and WhatsApp (docs/APP-1.0-PLAN.md §8): members' news consent from Accounts,
-- what each member chose the App sends them, what each outbox message went by, and the counts per day.
-- CreateEnum
CREATE TYPE "NotifyChoice" AS ENUM ('off', 'email', 'whatsapp', 'both');
-- AlterTable
ALTER TABLE "Member" ADD COLUMN "newsEmail" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN "newsWhatsApp" BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE "OutboxMessage" ADD COLUMN "sentVia" TEXT;
-- CreateTable
CREATE TABLE "NotificationSettings" (
"memberId" TEXT NOT NULL,
"requestUpdates" "NotifyChoice" NOT NULL DEFAULT 'email',
"announcements" "NotifyChoice" NOT NULL DEFAULT 'off',
"devotional" "NotifyChoice" NOT NULL DEFAULT 'off',
"devotionalTime" TEXT NOT NULL DEFAULT '06:00',
"devotionalOfferedAt" TIMESTAMP(3),
"lastDevotionalDate" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "NotificationSettings_pkey" PRIMARY KEY ("memberId")
);
-- CreateTable
CREATE TABLE "MessageCount" (
"key" TEXT NOT NULL,
"day" TEXT NOT NULL,
"channel" TEXT NOT NULL,
"count" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "MessageCount_pkey" PRIMARY KEY ("key")
);
-- CreateIndex
CREATE INDEX "NotificationSettings_devotional_idx" ON "NotificationSettings"("devotional");
-- CreateIndex
CREATE INDEX "MessageCount_day_idx" ON "MessageCount"("day");
-- AddForeignKey
ALTER TABLE "NotificationSettings" ADD CONSTRAINT "NotificationSettings_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE CASCADE ON UPDATE CASCADE;