Skip to content

feat(notifications): add scheduled digest email service#1014

Merged
Olowodarey merged 2 commits into
Arena1X:mainfrom
ussyalfaks:feat/notification-digest-service
Jun 23, 2026
Merged

feat(notifications): add scheduled digest email service#1014
Olowodarey merged 2 commits into
Arena1X:mainfrom
ussyalfaks:feat/notification-digest-service

Conversation

@ussyalfaks

@ussyalfaks ussyalfaks commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

closes #1006

  • Adds a digest_frequency column (daily | weekly | off, default off) to user_preferences so users can opt into digest emails
  • Adds a nullable email column to users (required to resolve a send address per user)
  • Introduces NotificationDigestState entity that tracks the last sent period per user (YYYY-MM-DD for daily, YYYY-WNN for weekly) to enforce idempotency
  • Adds DigestService with two configurable cron jobs (registered dynamically via SchedulerRegistry) that fan out per-user digest emails each daily/weekly period
  • Extends email-templates.ts with a digest template type that renders a bulleted HTML + plain-text summary of unread notifications

Behaviour

  • Users with digest_frequency = 'off' or email_notifications = false are never emailed
  • Users with no email on file are silently skipped
  • Users with no unread activity in the window receive no email (no empty digests)
  • Running the cron twice for the same period is a no-op — the period key is persisted on first send

Environment variables

Variable Default Description
DIGEST_ENABLED true Set to false to disable all digest jobs at startup
DIGEST_DAILY_HOUR_UTC 8 UTC hour the daily digest fires (0–23)
DIGEST_WEEKLY_DAY 1 Day of week for weekly digest (0=Sun … 6=Sat)

Test plan

  • Set digest_frequency = 'daily' and email_notifications = true on a user with unread notifications — confirm one email queued per day
  • Trigger the daily cron twice in the same UTC day — confirm second run sends nothing
  • Set email_notifications = false — confirm no email sent
  • Set digest_frequency = 'off' — confirm no email sent
  • Leave email null on a user — confirm skipped silently
  • User with zero unread notifications in the window — confirm no email queued
  • Run migration against a clean DB and verify all three schema changes apply cleanly

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview, Comment Jun 23, 2026 5:09am

@Olowodarey

Copy link
Copy Markdown
Collaborator

@ussyalfaks great job clean code

@Olowodarey Olowodarey merged commit 1ab863d into Arena1X:main Jun 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] — Scheduled notification digests (daily / weekly) honouring preferences

2 participants