2026-04-28 18:00:47 +02:00
|
|
|
import { NextResponse, type NextRequest } from 'next/server'
|
|
|
|
|
import { prisma } from '@/lib/prisma'
|
2026-06-04 16:17:19 +02:00
|
|
|
import {
|
|
|
|
|
expirePendingPastDeadline,
|
|
|
|
|
sendDueConfirmationReminders,
|
|
|
|
|
} from '@/server/services/finalist-confirmation'
|
2026-04-28 18:00:47 +02:00
|
|
|
|
|
|
|
|
export async function GET(request: NextRequest): Promise<NextResponse> {
|
|
|
|
|
const cronSecret = request.headers.get('x-cron-secret')
|
|
|
|
|
if (!cronSecret || cronSecret !== process.env.CRON_SECRET) {
|
|
|
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
|
|
|
}
|
|
|
|
|
try {
|
2026-06-04 16:17:19 +02:00
|
|
|
const [expireResult, reminderResult] = await Promise.all([
|
|
|
|
|
expirePendingPastDeadline(prisma),
|
|
|
|
|
sendDueConfirmationReminders(prisma),
|
|
|
|
|
])
|
|
|
|
|
return NextResponse.json({ ok: true, ...expireResult, ...reminderResult })
|
2026-04-28 18:00:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('[Cron] finalist-confirmations failed:', error)
|
|
|
|
|
return NextResponse.json({ error: 'Internal error' }, { status: 500 })
|
|
|
|
|
}
|
|
|
|
|
}
|