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:
@@ -32,20 +32,23 @@ enum AppRole {
|
||||
/// signed in is a Member; `roles` adds what the admin can do. A copy of the Accounts profile, kept
|
||||
/// up to date by `user.updated`.
|
||||
model Member {
|
||||
id String @id
|
||||
name String
|
||||
email String
|
||||
id String @id
|
||||
name String
|
||||
email String
|
||||
/// The verified number from Accounts (reminders by WhatsApp), or null.
|
||||
phone String?
|
||||
phone String?
|
||||
/// The person replied STOP to the church's WhatsApp number (decision 11): no WhatsApp of any kind.
|
||||
whatsappOptedOut Boolean @default(false)
|
||||
roles AppRole[] @default([])
|
||||
whatsappOptedOut Boolean @default(false)
|
||||
roles AppRole[] @default([])
|
||||
/// The last day they used the App signed in (written at most once a day): active members (§10).
|
||||
lastActiveAt DateTime?
|
||||
lastSignInAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
sessions Session[]
|
||||
lastActiveAt DateTime?
|
||||
lastSignInAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
sessions Session[]
|
||||
prayerCommitments PrayerCommitment[]
|
||||
testimonies Testimony[]
|
||||
outboxMessages OutboxMessage[]
|
||||
|
||||
@@index([lastActiveAt])
|
||||
}
|
||||
@@ -117,3 +120,167 @@ model AppSetting {
|
||||
value String
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
// ── House of Prayer (§3) ─────────────────────────────────────────────────────────────────────
|
||||
// The wall's rules (slot length, target, booking limits, the cancel window, the coordinator to
|
||||
// contact) are in AppSetting `prayer_wall`. Days are local dates (YYYY-MM-DD) in the church's
|
||||
// timezone; minutes are after local midnight (src/prayer/rules.ts).
|
||||
|
||||
enum PrayerRecurrence {
|
||||
once
|
||||
daily
|
||||
weekly
|
||||
}
|
||||
|
||||
/// When a member is reminded of a slot (P6): none, 15 minutes or an hour before, or 20:00 the evening before.
|
||||
enum PrayerReminder {
|
||||
none
|
||||
min15
|
||||
hour1
|
||||
evening
|
||||
}
|
||||
|
||||
/// How a member is reached for one kind of message (§8).
|
||||
enum MessageChannel {
|
||||
email
|
||||
whatsapp
|
||||
both
|
||||
}
|
||||
|
||||
/// A commitment to pray: a rule (start, length, recurrence, end) plus the dates skipped, never a
|
||||
/// row per occurrence (§3). The member's name is never in coverage; only the prayer team sees it.
|
||||
model PrayerCommitment {
|
||||
id String @id @default(uuid())
|
||||
/// Null once the member deleted their account: past occurrences stay as counts only (§11).
|
||||
memberId String?
|
||||
member Member? @relation(fields: [memberId], references: [id], onDelete: SetNull)
|
||||
/// The first local date it happens on (a weekly rule keeps this date's weekday).
|
||||
startDate String
|
||||
/// Minutes after local midnight (02:00 = 120), on a slot boundary when booked.
|
||||
startMinute Int
|
||||
durationMinutes Int
|
||||
recurrence PrayerRecurrence
|
||||
/// The last local date with an occurrence (a once rule: its start date).
|
||||
endDate String
|
||||
reminder PrayerReminder @default(hour1)
|
||||
/// Reminders and renewal notices for this commitment.
|
||||
channel MessageChannel @default(email)
|
||||
/// "Where I'll pray", for the member alone.
|
||||
note String?
|
||||
/// A prayer coordinator who booked it on the member's behalf.
|
||||
bookedById String?
|
||||
/// Renewal notices sent for the current end date: 0, 1 (14 days before) or 2 (3 days before).
|
||||
renewalNoticesSent Int @default(0)
|
||||
renewedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
skips PrayerSkip[]
|
||||
marks PrayedMark[]
|
||||
|
||||
@@index([endDate])
|
||||
@@index([memberId])
|
||||
}
|
||||
|
||||
/// One occurrence skipped ("Skip 14 December").
|
||||
model PrayerSkip {
|
||||
id String @id @default(uuid())
|
||||
commitmentId String
|
||||
commitment PrayerCommitment @relation(fields: [commitmentId], references: [id], onDelete: Cascade)
|
||||
date String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([commitmentId, date])
|
||||
}
|
||||
|
||||
/// "I prayed" for one occurrence: self-reported, counted as a number only, never a ranking (§3).
|
||||
model PrayedMark {
|
||||
id String @id @default(uuid())
|
||||
commitmentId String
|
||||
commitment PrayerCommitment @relation(fields: [commitmentId], references: [id], onDelete: Cascade)
|
||||
memberId String?
|
||||
date String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([commitmentId, date])
|
||||
@@index([date])
|
||||
}
|
||||
|
||||
/// A time-bound focus ("21 days of prayer", P7): collective coverage and hours prayed only.
|
||||
model PrayerCampaign {
|
||||
id String @id @default(uuid())
|
||||
title String
|
||||
description String
|
||||
imageUrl String?
|
||||
startDate String
|
||||
endDate String
|
||||
/// "Every hour covered", shown as the campaign's aim.
|
||||
goal String?
|
||||
/// The campaign's own people per slot, instead of the wall's target, while it runs.
|
||||
targetPerSlot Int?
|
||||
createdById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
testimonies Testimony[]
|
||||
|
||||
@@index([endDate])
|
||||
}
|
||||
|
||||
enum TestimonyStatus {
|
||||
pending
|
||||
approved
|
||||
removed
|
||||
}
|
||||
|
||||
/// What God has done, shared by a member: moderated before anyone sees it, the first name or
|
||||
/// "Anonymous", removable by its author at any time (§3). Deleted with the account (§11).
|
||||
model Testimony {
|
||||
id String @id @default(uuid())
|
||||
memberId String
|
||||
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade)
|
||||
campaignId String?
|
||||
campaign PrayerCampaign? @relation(fields: [campaignId], references: [id], onDelete: SetNull)
|
||||
text String
|
||||
showName Boolean @default(false)
|
||||
status TestimonyStatus @default(pending)
|
||||
/// Why a coordinator removed it (sent to the author).
|
||||
removedReason String?
|
||||
moderatedById String?
|
||||
moderatedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([status, createdAt])
|
||||
}
|
||||
|
||||
/// Who saw names (§3, §10 Access log): every view of bookings with names, and later of prayer requests.
|
||||
model AccessLog {
|
||||
id String @id @default(uuid())
|
||||
actorId String
|
||||
action String
|
||||
targetType String
|
||||
targetId String?
|
||||
metadata Json?
|
||||
ip String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
/// Email and WhatsApp to send (§8): reminders, renewal notices and later the modules' sends. Written
|
||||
/// once (`dedupeKey`), sent by the messaging job; what's in `payload` is the message's facts only.
|
||||
model OutboxMessage {
|
||||
id String @id @default(uuid())
|
||||
memberId String
|
||||
member Member @relation(fields: [memberId], references: [id], onDelete: Cascade)
|
||||
kind String
|
||||
channel MessageChannel
|
||||
payload Json
|
||||
dedupeKey String @unique
|
||||
sendAfter DateTime
|
||||
sentAt DateTime?
|
||||
failedAt DateTime?
|
||||
error String?
|
||||
attempts Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([sentAt, sendAfter])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user