app: the House of Prayer's backend (APP-1.0-PLAN §3)
Commitments stored as rules (start, length, once/daily/weekly, end, skips) in the church's timezone, daylight saving included; the day's coverage as counts only, cached until a booking changes, live over server-sent events (X-Accel-Buffering off, a comment every 25 s). Booking, skipping, changing, cancelling within the 8-hour rule, renewing (a signed single-use link), "I prayed" (self-reported). Campaigns and moderated testimonies; the admin's bookings with names, always access-logged; booking on a member's behalf. Reminders (every minute) and renewal notices (14 and 3 days before) queued in an outbox for the messaging slice. The heartbeat's prayer counts; export and delete for a member's prayer. Migration 20261202000000_house_of_prayer (checked on PostgreSQL 18: applies, no diff). 66 backend tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Messages to send (APP-1.0-PLAN §8), written once each (`dedupeKey`) by whatever decides one is
|
||||
* due: prayer reminders and renewal notices (prayer/jobs.ts), and the later modules' sends. The
|
||||
* messaging job sends them by email and/or WhatsApp with the church's settings from Accounts,
|
||||
* checking the WhatsApp STOP first (§8, decision 11).
|
||||
*
|
||||
* `payload` holds the facts the message is built from (times, links), never a prayer request's text.
|
||||
*/
|
||||
import type { Ctx } from '../context.js';
|
||||
|
||||
export type OutboxKind = 'prayer-reminder' | 'prayer-renewal' | 'testimony-removed';
|
||||
export type Channel = 'email' | 'whatsapp' | 'both';
|
||||
|
||||
/** Queues a message; false when one with the same key was already queued (never sent twice). */
|
||||
export async function enqueue(ctx: Ctx, m: { memberId: string; kind: OutboxKind; channel: Channel; dedupeKey: string; payload: object; sendAfter?: Date }): Promise<boolean> {
|
||||
try {
|
||||
await ctx.db.outboxMessage.create({ data: { memberId: m.memberId, kind: m.kind, channel: m.channel, dedupeKey: m.dedupeKey, payload: m.payload as never, sendAfter: m.sendAfter ?? ctx.now() } });
|
||||
return true;
|
||||
} catch (e) {
|
||||
if ((e as { code?: string }).code === 'P2002') return false;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user