2026-02-14 15:26:42 +01:00
|
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
|
import { sendStyledNotificationEmail } from '@/lib/email'
|
|
|
|
|
|
|
|
|
|
const REMINDER_TYPES = [
|
|
|
|
|
{ type: '3_DAYS', thresholdMs: 3 * 24 * 60 * 60 * 1000 },
|
|
|
|
|
{ type: '24H', thresholdMs: 24 * 60 * 60 * 1000 },
|
|
|
|
|
{ type: '1H', thresholdMs: 60 * 60 * 1000 },
|
|
|
|
|
] as const
|
|
|
|
|
|
|
|
|
|
type ReminderType = (typeof REMINDER_TYPES)[number]['type']
|
|
|
|
|
|
|
|
|
|
interface ReminderResult {
|
|
|
|
|
sent: number
|
|
|
|
|
errors: number
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 12:15:51 +01:00
|
|
|
/**
|
|
|
|
|
* Manually send reminders to all jurors with incomplete assignments for a round.
|
|
|
|
|
* Bypasses window/deadline checks — the admin explicitly chose to send now.
|
|
|
|
|
* Uses 'MANUAL' type so it doesn't interfere with automated cron deduplication,
|
|
|
|
|
* but still deduplicates within manual sends (one manual reminder per juror per round).
|
|
|
|
|
*/
|
|
|
|
|
export async function sendManualReminders(roundId: string): Promise<ReminderResult> {
|
|
|
|
|
let sent = 0
|
|
|
|
|
let errors = 0
|
|
|
|
|
|
|
|
|
|
const round = await prisma.round.findUnique({
|
|
|
|
|
where: { id: roundId },
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
windowCloseAt: true,
|
|
|
|
|
competition: { select: { name: true } },
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!round) return { sent, errors }
|
|
|
|
|
|
|
|
|
|
// Find jurors with incomplete assignments
|
|
|
|
|
const incompleteAssignments = await prisma.assignment.findMany({
|
|
|
|
|
where: { roundId, isCompleted: false },
|
|
|
|
|
select: { userId: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const userIds = [...new Set(incompleteAssignments.map((a) => a.userId))]
|
|
|
|
|
if (userIds.length === 0) return { sent, errors }
|
|
|
|
|
|
|
|
|
|
// Deduplicate: only one MANUAL reminder per juror per round
|
|
|
|
|
const existingManual = await prisma.reminderLog.findMany({
|
|
|
|
|
where: { roundId, type: 'MANUAL', userId: { in: userIds } },
|
|
|
|
|
select: { userId: true },
|
|
|
|
|
})
|
|
|
|
|
const alreadySent = new Set(existingManual.map((r) => r.userId))
|
|
|
|
|
const usersToNotify = userIds.filter((id) => !alreadySent.has(id))
|
|
|
|
|
|
|
|
|
|
if (usersToNotify.length === 0) return { sent, errors }
|
|
|
|
|
|
|
|
|
|
const users = await prisma.user.findMany({
|
|
|
|
|
where: { id: { in: usersToNotify } },
|
|
|
|
|
select: { id: true, name: true, email: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const baseUrl = process.env.NEXTAUTH_URL || 'https://monaco-opc.com'
|
|
|
|
|
const deadlineStr = round.windowCloseAt
|
|
|
|
|
? round.windowCloseAt.toLocaleDateString('en-US', {
|
|
|
|
|
weekday: 'long',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
timeZoneName: 'short',
|
|
|
|
|
})
|
|
|
|
|
: undefined
|
|
|
|
|
|
|
|
|
|
const pendingCounts = new Map<string, number>()
|
|
|
|
|
for (const a of incompleteAssignments) {
|
|
|
|
|
pendingCounts.set(a.userId, (pendingCounts.get(a.userId) || 0) + 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const user of users) {
|
|
|
|
|
const pendingCount = pendingCounts.get(user.id) || 0
|
|
|
|
|
if (pendingCount === 0) continue
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const deadlineNote = deadlineStr ? ` The deadline is ${deadlineStr}.` : ''
|
|
|
|
|
await sendStyledNotificationEmail(
|
|
|
|
|
user.email,
|
|
|
|
|
user.name || '',
|
|
|
|
|
'REMINDER_24H',
|
|
|
|
|
{
|
|
|
|
|
name: user.name || undefined,
|
|
|
|
|
title: `Evaluation Reminder - ${round.name}`,
|
|
|
|
|
message: `You have ${pendingCount} pending evaluation${pendingCount !== 1 ? 's' : ''} for ${round.name}.${deadlineNote}`,
|
|
|
|
|
linkUrl: `${baseUrl}/jury/rounds/${round.id}/assignments`,
|
|
|
|
|
metadata: {
|
|
|
|
|
pendingCount,
|
|
|
|
|
roundName: round.name,
|
|
|
|
|
...(deadlineStr && { deadline: deadlineStr }),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await prisma.reminderLog.create({
|
|
|
|
|
data: { roundId, userId: user.id, type: 'MANUAL' },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
sent++
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(
|
|
|
|
|
`Failed to send manual reminder to ${user.email} for round ${round.name}:`,
|
|
|
|
|
error
|
|
|
|
|
)
|
|
|
|
|
errors++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { sent, errors }
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 15:26:42 +01:00
|
|
|
/**
|
|
|
|
|
* Find active stages with approaching deadlines and send reminders
|
2026-02-19 12:15:51 +01:00
|
|
|
* to jurors who have incomplete assignments. (Used by cron job)
|
2026-02-14 15:26:42 +01:00
|
|
|
*/
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
export async function processEvaluationReminders(roundId?: string): Promise<ReminderResult> {
|
2026-02-14 15:26:42 +01:00
|
|
|
const now = new Date()
|
|
|
|
|
let totalSent = 0
|
|
|
|
|
let totalErrors = 0
|
|
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
// Find active rounds with window close dates in the future
|
|
|
|
|
const rounds = await prisma.round.findMany({
|
2026-02-14 15:26:42 +01:00
|
|
|
where: {
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
status: 'ROUND_ACTIVE' as const,
|
2026-02-14 15:26:42 +01:00
|
|
|
windowCloseAt: { gt: now },
|
|
|
|
|
windowOpenAt: { lte: now },
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
...(roundId && { id: roundId }),
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
windowCloseAt: true,
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
competition: { select: { name: true } },
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
for (const round of rounds) {
|
|
|
|
|
if (!round.windowCloseAt) continue
|
2026-02-14 15:26:42 +01:00
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
const msUntilDeadline = round.windowCloseAt.getTime() - now.getTime()
|
2026-02-14 15:26:42 +01:00
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
// Determine which reminder types should fire for this round
|
2026-02-14 15:26:42 +01:00
|
|
|
const applicableTypes = REMINDER_TYPES.filter(
|
|
|
|
|
({ thresholdMs }) => msUntilDeadline <= thresholdMs
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (applicableTypes.length === 0) continue
|
|
|
|
|
|
|
|
|
|
for (const { type } of applicableTypes) {
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
const result = await sendRemindersForRound(round, type, now)
|
2026-02-14 15:26:42 +01:00
|
|
|
totalSent += result.sent
|
|
|
|
|
totalErrors += result.errors
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { sent: totalSent, errors: totalErrors }
|
|
|
|
|
}
|
|
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
async function sendRemindersForRound(
|
|
|
|
|
round: {
|
2026-02-14 15:26:42 +01:00
|
|
|
id: string
|
|
|
|
|
name: string
|
|
|
|
|
windowCloseAt: Date | null
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
competition: { name: string } | null
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
type: ReminderType,
|
|
|
|
|
now: Date
|
|
|
|
|
): Promise<ReminderResult> {
|
|
|
|
|
let sent = 0
|
|
|
|
|
let errors = 0
|
|
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
if (!round.windowCloseAt) return { sent, errors }
|
2026-02-14 15:26:42 +01:00
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
// Find jurors with incomplete assignments for this round
|
2026-02-14 15:26:42 +01:00
|
|
|
const incompleteAssignments = await prisma.assignment.findMany({
|
|
|
|
|
where: {
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
roundId: round.id,
|
2026-02-14 15:26:42 +01:00
|
|
|
isCompleted: false,
|
|
|
|
|
},
|
|
|
|
|
select: {
|
|
|
|
|
userId: true,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Get unique user IDs with incomplete work
|
|
|
|
|
const userIds = [...new Set(incompleteAssignments.map((a) => a.userId))]
|
|
|
|
|
|
|
|
|
|
if (userIds.length === 0) return { sent, errors }
|
|
|
|
|
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
// Check which users already received this reminder type for this round
|
2026-02-14 15:26:42 +01:00
|
|
|
const existingReminders = await prisma.reminderLog.findMany({
|
|
|
|
|
where: {
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
roundId: round.id,
|
2026-02-14 15:26:42 +01:00
|
|
|
type,
|
|
|
|
|
userId: { in: userIds },
|
|
|
|
|
},
|
|
|
|
|
select: { userId: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const alreadySent = new Set(existingReminders.map((r) => r.userId))
|
|
|
|
|
const usersToNotify = userIds.filter((id) => !alreadySent.has(id))
|
|
|
|
|
|
|
|
|
|
if (usersToNotify.length === 0) return { sent, errors }
|
|
|
|
|
|
|
|
|
|
// Get user details and their pending counts
|
|
|
|
|
const users = await prisma.user.findMany({
|
|
|
|
|
where: { id: { in: usersToNotify } },
|
|
|
|
|
select: { id: true, name: true, email: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const baseUrl = process.env.NEXTAUTH_URL || 'https://monaco-opc.com'
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
const deadlineStr = round.windowCloseAt.toLocaleDateString('en-US', {
|
2026-02-14 15:26:42 +01:00
|
|
|
weekday: 'long',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
month: 'long',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
minute: '2-digit',
|
|
|
|
|
timeZoneName: 'short',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Map to get pending count per user
|
|
|
|
|
const pendingCounts = new Map<string, number>()
|
|
|
|
|
for (const a of incompleteAssignments) {
|
|
|
|
|
pendingCounts.set(a.userId, (pendingCounts.get(a.userId) || 0) + 1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Select email template type based on reminder type
|
|
|
|
|
const emailTemplateType = type === '1H' ? 'REMINDER_1H' : 'REMINDER_24H'
|
|
|
|
|
|
|
|
|
|
for (const user of users) {
|
|
|
|
|
const pendingCount = pendingCounts.get(user.id) || 0
|
|
|
|
|
if (pendingCount === 0) continue
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await sendStyledNotificationEmail(
|
|
|
|
|
user.email,
|
|
|
|
|
user.name || '',
|
|
|
|
|
emailTemplateType,
|
|
|
|
|
{
|
|
|
|
|
name: user.name || undefined,
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
title: `Evaluation Reminder - ${round.name}`,
|
|
|
|
|
message: `You have ${pendingCount} pending evaluation${pendingCount !== 1 ? 's' : ''} for ${round.name}.`,
|
|
|
|
|
linkUrl: `${baseUrl}/jury/rounds/${round.id}/assignments`,
|
2026-02-14 15:26:42 +01:00
|
|
|
metadata: {
|
|
|
|
|
pendingCount,
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
roundName: round.name,
|
2026-02-14 15:26:42 +01:00
|
|
|
deadline: deadlineStr,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Log the sent reminder
|
|
|
|
|
await prisma.reminderLog.create({
|
|
|
|
|
data: {
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
roundId: round.id,
|
2026-02-14 15:26:42 +01:00
|
|
|
userId: user.id,
|
|
|
|
|
type,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
sent++
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(
|
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00
|
|
|
`Failed to send ${type} reminder to ${user.email} for round ${round.name}:`,
|
2026-02-14 15:26:42 +01:00
|
|
|
error
|
|
|
|
|
)
|
|
|
|
|
errors++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { sent, errors }
|
|
|
|
|
}
|