2026-02-14 15:26:42 +01:00
|
|
|
import { z } from 'zod'
|
|
|
|
|
import { router, adminProcedure } from '../trpc'
|
|
|
|
|
|
|
|
|
|
export const dashboardRouter = router({
|
|
|
|
|
/**
|
|
|
|
|
* Get all dashboard stats in a single query batch.
|
|
|
|
|
* Replaces the 16 parallel Prisma queries that were previously
|
|
|
|
|
* run during SSR, which blocked the event loop and caused 503s.
|
|
|
|
|
*/
|
|
|
|
|
getStats: adminProcedure
|
|
|
|
|
.input(z.object({ editionId: z.string() }))
|
|
|
|
|
.query(async ({ ctx, input }) => {
|
|
|
|
|
const { editionId } = input
|
|
|
|
|
|
|
|
|
|
const edition = await ctx.prisma.program.findUnique({
|
|
|
|
|
where: { id: editionId },
|
|
|
|
|
select: { name: true, year: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!edition) return null
|
|
|
|
|
|
|
|
|
|
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
|
|
|
|
|
|
|
|
|
|
const [
|
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
|
|
|
activeRoundCount,
|
|
|
|
|
totalRoundCount,
|
2026-02-14 15:26:42 +01:00
|
|
|
projectCount,
|
|
|
|
|
newProjectsThisWeek,
|
|
|
|
|
totalJurors,
|
|
|
|
|
activeJurors,
|
|
|
|
|
evaluationStats,
|
|
|
|
|
totalAssignments,
|
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
|
|
|
recentRounds,
|
2026-02-14 15:26:42 +01:00
|
|
|
latestProjects,
|
|
|
|
|
categoryBreakdown,
|
|
|
|
|
oceanIssueBreakdown,
|
|
|
|
|
recentActivity,
|
|
|
|
|
pendingCOIs,
|
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
|
|
|
draftRounds,
|
2026-02-14 15:26:42 +01:00
|
|
|
unassignedProjects,
|
|
|
|
|
] = await Promise.all([
|
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
|
|
|
ctx.prisma.round.count({
|
|
|
|
|
where: { competition: { programId: editionId }, status: 'ROUND_ACTIVE' },
|
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
|
|
|
ctx.prisma.round.count({
|
|
|
|
|
where: { competition: { programId: editionId } },
|
2026-02-14 15:26:42 +01:00
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.count({
|
|
|
|
|
where: { programId: editionId },
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.count({
|
|
|
|
|
where: {
|
|
|
|
|
programId: editionId,
|
|
|
|
|
createdAt: { gte: sevenDaysAgo },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.user.count({
|
|
|
|
|
where: {
|
|
|
|
|
role: 'JURY_MEMBER',
|
|
|
|
|
status: { in: ['ACTIVE', 'INVITED', 'NONE'] },
|
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
|
|
|
assignments: { some: { round: { competition: { programId: editionId } } } },
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.user.count({
|
|
|
|
|
where: {
|
|
|
|
|
role: 'JURY_MEMBER',
|
|
|
|
|
status: 'ACTIVE',
|
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
|
|
|
assignments: { some: { round: { competition: { programId: editionId } } } },
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.evaluation.groupBy({
|
|
|
|
|
by: ['status'],
|
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
|
|
|
where: { assignment: { round: { competition: { programId: editionId } } } },
|
2026-02-14 15:26:42 +01:00
|
|
|
_count: true,
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.assignment.count({
|
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
|
|
|
where: { round: { competition: { programId: editionId } } },
|
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
|
|
|
ctx.prisma.round.findMany({
|
|
|
|
|
where: { competition: { programId: editionId } },
|
2026-02-14 15:26:42 +01:00
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
take: 5,
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
status: 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
|
|
|
roundType: true,
|
2026-02-14 15:26:42 +01:00
|
|
|
windowOpenAt: true,
|
|
|
|
|
windowCloseAt: true,
|
|
|
|
|
_count: {
|
|
|
|
|
select: {
|
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
|
|
|
projectRoundStates: true,
|
2026-02-14 15:26:42 +01:00
|
|
|
assignments: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
assignments: {
|
|
|
|
|
select: {
|
|
|
|
|
evaluation: { select: { status: true } },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.findMany({
|
|
|
|
|
where: { programId: editionId },
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
take: 8,
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
title: true,
|
|
|
|
|
teamName: true,
|
|
|
|
|
country: true,
|
|
|
|
|
competitionCategory: true,
|
|
|
|
|
oceanIssue: true,
|
|
|
|
|
logoKey: true,
|
|
|
|
|
createdAt: true,
|
|
|
|
|
submittedAt: true,
|
|
|
|
|
status: true,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.groupBy({
|
|
|
|
|
by: ['competitionCategory'],
|
|
|
|
|
where: { programId: editionId },
|
|
|
|
|
_count: true,
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.groupBy({
|
|
|
|
|
by: ['oceanIssue'],
|
|
|
|
|
where: { programId: editionId },
|
|
|
|
|
_count: true,
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.auditLog.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
timestamp: { gte: sevenDaysAgo },
|
|
|
|
|
},
|
|
|
|
|
orderBy: { timestamp: 'desc' },
|
|
|
|
|
take: 8,
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
action: true,
|
|
|
|
|
entityType: true,
|
|
|
|
|
timestamp: true,
|
|
|
|
|
user: { select: { name: true } },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.conflictOfInterest.count({
|
|
|
|
|
where: {
|
|
|
|
|
hasConflict: true,
|
|
|
|
|
reviewedAt: 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
|
|
|
assignment: { round: { competition: { programId: editionId } } },
|
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
|
|
|
ctx.prisma.round.count({
|
|
|
|
|
where: { competition: { programId: editionId }, status: 'ROUND_DRAFT' },
|
2026-02-14 15:26:42 +01:00
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.count({
|
|
|
|
|
where: {
|
|
|
|
|
programId: editionId,
|
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
|
|
|
projectRoundStates: {
|
2026-02-14 15:26:42 +01:00
|
|
|
some: {
|
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
|
|
|
round: { status: 'ROUND_ACTIVE' },
|
2026-02-14 15:26:42 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
assignments: { none: {} },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
edition,
|
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
|
|
|
activeRoundCount,
|
|
|
|
|
totalRoundCount,
|
2026-02-14 15:26:42 +01:00
|
|
|
projectCount,
|
|
|
|
|
newProjectsThisWeek,
|
|
|
|
|
totalJurors,
|
|
|
|
|
activeJurors,
|
|
|
|
|
evaluationStats,
|
|
|
|
|
totalAssignments,
|
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
|
|
|
recentRounds,
|
2026-02-14 15:26:42 +01:00
|
|
|
latestProjects,
|
|
|
|
|
categoryBreakdown,
|
|
|
|
|
oceanIssueBreakdown,
|
|
|
|
|
recentActivity,
|
|
|
|
|
pendingCOIs,
|
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
|
|
|
draftRounds,
|
2026-02-14 15:26:42 +01:00
|
|
|
unassignedProjects,
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
})
|