feat(finalist): deadline reminder emails via cron
Add sendDueConfirmationReminders() to finalist-confirmation.ts: queries PENDING confirmations with no reminderSentAt whose deadline is within the per-program LIVE_FINAL round reminderHoursBeforeDeadline window (default 12h), sends a FINALIST_REMINDER in-app notification (+ email via pipeline) to the team LEAD, then stamps reminderSentAt for idempotency. Wire into the finalist-confirmations cron route alongside expirePendingPastDeadline. Also clear reminderSentAt on re-invite in resetOrCreatePendingConfirmation so re-invited teams get a fresh reminder window. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { expirePendingPastDeadline } from '@/server/services/finalist-confirmation'
|
||||
import {
|
||||
expirePendingPastDeadline,
|
||||
sendDueConfirmationReminders,
|
||||
} from '@/server/services/finalist-confirmation'
|
||||
|
||||
export async function GET(request: NextRequest): Promise<NextResponse> {
|
||||
const cronSecret = request.headers.get('x-cron-secret')
|
||||
@@ -8,8 +11,11 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
try {
|
||||
const result = await expirePendingPastDeadline(prisma)
|
||||
return NextResponse.json({ ok: true, ...result })
|
||||
const [expireResult, reminderResult] = await Promise.all([
|
||||
expirePendingPastDeadline(prisma),
|
||||
sendDueConfirmationReminders(prisma),
|
||||
])
|
||||
return NextResponse.json({ ok: true, ...expireResult, ...reminderResult })
|
||||
} catch (error) {
|
||||
console.error('[Cron] finalist-confirmations failed:', error)
|
||||
return NextResponse.json({ error: 'Internal error' }, { status: 500 })
|
||||
|
||||
Reference in New Issue
Block a user