Implement notifications cron endpoint (P2.5)
Add daily email notification system that sends training decisions at each user's preferred time in their timezone. Features: - Timezone-aware notification matching using Intl.DateTimeFormat - DailyLog-based notifications with duplicate prevention - Nutrition guidance integration via getNutritionGuidance - Graceful error handling (continues processing on per-user failures) - Summary response with detailed stats Includes 20 tests covering: - CRON_SECRET authentication - Timezone matching (UTC and America/New_York) - DailyLog existence and already-sent checks - Email content assembly - Error handling and response format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
|
||||
| GET /api/calendar/[userId]/[token].ics | 501 | Has param extraction, core logic TODO |
|
||||
| POST /api/calendar/regenerate-token | 501 | Returns Not Implemented |
|
||||
| POST /api/cron/garmin-sync | **COMPLETE** | Syncs Garmin data for all users, creates DailyLogs (22 tests) |
|
||||
| POST /api/cron/notifications | 501 | Has CRON_SECRET auth check, core logic TODO |
|
||||
| POST /api/cron/notifications | **COMPLETE** | Sends daily emails with timezone matching, DailyLog handling (20 tests) |
|
||||
|
||||
### Pages (7 total)
|
||||
| Page | Status | Notes |
|
||||
@@ -308,15 +308,21 @@ Full feature set for production use.
|
||||
- **Why:** Automated data sync is required for morning notifications
|
||||
- **Depends On:** P2.1, P2.2
|
||||
|
||||
### P2.5: POST /api/cron/notifications Implementation
|
||||
- [ ] Send daily email notifications at user's preferred time
|
||||
### P2.5: POST /api/cron/notifications Implementation ✅ COMPLETE
|
||||
- [x] Send daily email notifications at user's preferred time
|
||||
- **Files:**
|
||||
- `src/app/api/cron/notifications/route.ts` - Find users by hour, compute decision, send email
|
||||
- `src/app/api/cron/notifications/route.ts` - Timezone-aware user matching, DailyLog fallback, email sending
|
||||
- **Tests:**
|
||||
- `src/app/api/cron/notifications/route.test.ts` - Test timezone handling, duplicate prevention
|
||||
- `src/app/api/cron/notifications/route.test.ts` - 20 tests covering timezone matching, DailyLog handling, email sending
|
||||
- **Features Implemented:**
|
||||
- Timezone-aware notification matching (finds users whose notificationTime matches current hour in their timezone)
|
||||
- DailyLog-based notifications with fallback to real-time calculation when DailyLog missing
|
||||
- Duplicate prevention (only sends once per user per hour)
|
||||
- Nutrition guidance integration (seeds, carbs, keto)
|
||||
- CRON_SECRET authentication
|
||||
- Returns summary with emailsSent count and timestamp
|
||||
- **Why:** Email notifications are a key feature per spec
|
||||
- **Depends On:** P2.4
|
||||
- **Note:** Route exists with CRON_SECRET auth check, needs core logic
|
||||
|
||||
### P2.6: GET /api/calendar/[userId]/[token].ics Implementation
|
||||
- [ ] Return ICS feed for calendar subscription
|
||||
@@ -577,6 +583,7 @@ P2.14 Mini calendar
|
||||
- [x] **DELETE /api/garmin/tokens** - Clears tokens and disconnects Garmin, 15 tests (P2.2)
|
||||
- [x] **GET /api/garmin/status** - Returns connection status, expiry, warning level, 11 tests (P2.3)
|
||||
- [x] **POST /api/cron/garmin-sync** - Daily sync of Garmin data for all connected users, creates DailyLogs, 22 tests (P2.4)
|
||||
- [x] **POST /api/cron/notifications** - Sends daily email notifications with timezone matching, DailyLog handling, nutrition guidance, 20 tests (P2.5)
|
||||
|
||||
### Pages
|
||||
- [x] **Login Page** - Email/password form with PocketBase auth, error handling, loading states, redirect, 14 tests (P1.6)
|
||||
|
||||
Reference in New Issue
Block a user