Create a module that reads upcoming appointments from the database and sends email reminders to patients. Function: ```typescript sendAppointmentReminders(daysAhead: number): Promise<ReminderResult> // ReminderResult: { sent: number, failed: number, skipped: number, errors: string[] } ``` Requirements: 1. Query appointments where `appointment_date` is within the next `daysAhead` days AND `reminder_sent_at IS NULL` 2. Send reminder emails via Resend (`RESEND_API_KEY` env var). If not set, log to console instead (dev fallback) 3. Email subject: `Reminder: Your appointment on [date] at [time]` 4. After successful send, set `reminder_sent_at = now()` on the appointment row 5. Retry failed sends up to 3 times with 2s exponential backoff 6. Idempotency: a second call within the same hour should skip already-reminded appointments 7. Return a summary of sent, failed, and skipped counts Write integration tests using a real test database (not mocks). Cover: normal send, missing email address, already-reminded guard.
No contributions yet.