2026-01-30 13:41:32 +01:00
|
|
|
import { z } from 'zod'
|
|
|
|
|
import { TRPCError } from '@trpc/server'
|
|
|
|
|
import { Prisma } from '@prisma/client'
|
|
|
|
|
import { router, protectedProcedure, adminProcedure } from '../trpc'
|
2026-02-02 13:19:28 +01:00
|
|
|
import { getUserAvatarUrl } from '../utils/avatar-url'
|
2026-02-04 00:10:51 +01:00
|
|
|
import {
|
|
|
|
|
notifyProjectTeam,
|
|
|
|
|
NotificationTypes,
|
|
|
|
|
} from '../services/in-app-notification'
|
2026-02-04 16:13:40 +01:00
|
|
|
import { normalizeCountryToCode } from '@/lib/countries'
|
2026-02-05 21:09:06 +01:00
|
|
|
import { logAudit } from '../utils/audit'
|
2026-01-30 13:41:32 +01:00
|
|
|
|
|
|
|
|
export const projectRouter = router({
|
|
|
|
|
/**
|
|
|
|
|
* List projects with filtering and pagination
|
|
|
|
|
* Admin sees all, jury sees only assigned projects
|
|
|
|
|
*/
|
|
|
|
|
list: protectedProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
2026-02-02 22:33:55 +01:00
|
|
|
programId: z.string().optional(),
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
roundId: z.string().optional(),
|
2026-01-30 13:41:32 +01:00
|
|
|
status: z
|
|
|
|
|
.enum([
|
|
|
|
|
'SUBMITTED',
|
|
|
|
|
'ELIGIBLE',
|
|
|
|
|
'ASSIGNED',
|
|
|
|
|
'SEMIFINALIST',
|
|
|
|
|
'FINALIST',
|
|
|
|
|
'REJECTED',
|
|
|
|
|
])
|
|
|
|
|
.optional(),
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
statuses: z.array(
|
|
|
|
|
z.enum([
|
|
|
|
|
'SUBMITTED',
|
|
|
|
|
'ELIGIBLE',
|
|
|
|
|
'ASSIGNED',
|
|
|
|
|
'SEMIFINALIST',
|
|
|
|
|
'FINALIST',
|
|
|
|
|
'REJECTED',
|
|
|
|
|
])
|
|
|
|
|
).optional(),
|
2026-02-02 22:33:55 +01:00
|
|
|
notInRoundId: z.string().optional(), // Exclude projects already in this round
|
|
|
|
|
unassignedOnly: z.boolean().optional(), // Projects not in any round
|
2026-01-30 13:41:32 +01:00
|
|
|
search: z.string().optional(),
|
|
|
|
|
tags: z.array(z.string()).optional(),
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
competitionCategory: z.enum(['STARTUP', 'BUSINESS_CONCEPT']).optional(),
|
|
|
|
|
oceanIssue: z.enum([
|
|
|
|
|
'POLLUTION_REDUCTION', 'CLIMATE_MITIGATION', 'TECHNOLOGY_INNOVATION',
|
|
|
|
|
'SUSTAINABLE_SHIPPING', 'BLUE_CARBON', 'HABITAT_RESTORATION',
|
|
|
|
|
'COMMUNITY_CAPACITY', 'SUSTAINABLE_FISHING', 'CONSUMER_AWARENESS',
|
|
|
|
|
'OCEAN_ACIDIFICATION', 'OTHER',
|
|
|
|
|
]).optional(),
|
|
|
|
|
country: z.string().optional(),
|
|
|
|
|
wantsMentorship: z.boolean().optional(),
|
|
|
|
|
hasFiles: z.boolean().optional(),
|
|
|
|
|
hasAssignments: z.boolean().optional(),
|
2026-01-30 13:41:32 +01:00
|
|
|
page: z.number().int().min(1).default(1),
|
2026-02-05 20:31:08 +01:00
|
|
|
perPage: z.number().int().min(1).max(200).default(20),
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.query(async ({ ctx, input }) => {
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
const {
|
2026-02-02 22:33:55 +01:00
|
|
|
programId, roundId, notInRoundId, status, statuses, unassignedOnly, search, tags,
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
competitionCategory, oceanIssue, country,
|
|
|
|
|
wantsMentorship, hasFiles, hasAssignments,
|
|
|
|
|
page, perPage,
|
|
|
|
|
} = input
|
2026-01-30 13:41:32 +01:00
|
|
|
const skip = (page - 1) * perPage
|
|
|
|
|
|
|
|
|
|
// Build where clause
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
const where: Record<string, unknown> = {}
|
2026-01-30 13:41:32 +01:00
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Filter by program via round
|
|
|
|
|
if (programId) where.round = { programId }
|
2026-02-02 22:33:55 +01:00
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Filter by round
|
2026-02-02 22:33:55 +01:00
|
|
|
if (roundId) {
|
2026-02-04 14:15:06 +01:00
|
|
|
where.roundId = roundId
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Exclude projects in a specific round
|
2026-02-02 22:33:55 +01:00
|
|
|
if (notInRoundId) {
|
2026-02-04 14:15:06 +01:00
|
|
|
where.roundId = { not: notInRoundId }
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Filter by unassigned (no round)
|
2026-02-02 22:33:55 +01:00
|
|
|
if (unassignedOnly) {
|
2026-02-04 14:15:06 +01:00
|
|
|
where.roundId = null
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Status filter
|
|
|
|
|
if (statuses?.length || status) {
|
2026-02-02 22:33:55 +01:00
|
|
|
const statusValues = statuses?.length ? statuses : status ? [status] : []
|
|
|
|
|
if (statusValues.length > 0) {
|
2026-02-04 14:15:06 +01:00
|
|
|
where.status = { in: statusValues }
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
}
|
2026-02-02 22:33:55 +01:00
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
if (tags && tags.length > 0) {
|
|
|
|
|
where.tags = { hasSome: tags }
|
|
|
|
|
}
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
if (competitionCategory) where.competitionCategory = competitionCategory
|
|
|
|
|
if (oceanIssue) where.oceanIssue = oceanIssue
|
|
|
|
|
if (country) where.country = country
|
|
|
|
|
if (wantsMentorship !== undefined) where.wantsMentorship = wantsMentorship
|
|
|
|
|
if (hasFiles === true) where.files = { some: {} }
|
|
|
|
|
if (hasFiles === false) where.files = { none: {} }
|
|
|
|
|
if (hasAssignments === true) where.assignments = { some: {} }
|
|
|
|
|
if (hasAssignments === false) where.assignments = { none: {} }
|
|
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
if (search) {
|
|
|
|
|
where.OR = [
|
|
|
|
|
{ title: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
{ teamName: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
{ description: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Jury members can only see assigned projects
|
|
|
|
|
if (ctx.user.role === 'JURY_MEMBER') {
|
|
|
|
|
where.assignments = {
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
...((where.assignments as Record<string, unknown>) || {}),
|
2026-01-30 13:41:32 +01:00
|
|
|
some: { userId: ctx.user.id },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [projects, total] = await Promise.all([
|
|
|
|
|
ctx.prisma.project.findMany({
|
|
|
|
|
where,
|
|
|
|
|
skip,
|
|
|
|
|
take: perPage,
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
include: {
|
2026-02-04 14:15:06 +01:00
|
|
|
round: {
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
name: true,
|
|
|
|
|
program: { select: { id: true, name: true, year: true } },
|
2026-02-02 22:33:55 +01:00
|
|
|
},
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
},
|
2026-02-05 20:31:08 +01:00
|
|
|
_count: { select: { assignments: true, files: true } },
|
2026-01-30 13:41:32 +01:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.count({ where }),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
projects,
|
|
|
|
|
total,
|
|
|
|
|
page,
|
|
|
|
|
perPage,
|
|
|
|
|
totalPages: Math.ceil(total / perPage),
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
/**
|
|
|
|
|
* Get filter options for the project list (distinct values)
|
|
|
|
|
*/
|
|
|
|
|
getFilterOptions: protectedProcedure
|
|
|
|
|
.query(async ({ ctx }) => {
|
|
|
|
|
const [rounds, countries, categories, issues] = await Promise.all([
|
|
|
|
|
ctx.prisma.round.findMany({
|
2026-02-05 10:27:52 +01:00
|
|
|
select: { id: true, name: true, program: { select: { id: true, name: true, year: true } } },
|
2026-02-04 14:15:06 +01:00
|
|
|
orderBy: [{ program: { year: 'desc' } }, { createdAt: 'asc' }],
|
Implement Prototype 1 improvements: unified members, project filters, audit expansion, filtering rounds, special awards
- Unified Member Management: merge /admin/users and /admin/mentors into /admin/members with role tabs, search, pagination
- Project List Filters: add search, multi-status filter, round/category/country selects, boolean toggles, URL persistence
- Audit Log Expansion: track logins, round state changes, evaluation submissions, file access, role changes via shared logAudit utility
- Founding Date Field: add foundedAt to Project model with CSV import support
- Filtering Round System: configurable rules (field-based, document check, AI screening), execution engine, results review with override/reinstate
- Special Awards System: named awards with eligibility criteria, dedicated jury, PICK_WINNER/RANKED/SCORED voting modes, AI eligibility
- Dashboard resilience: wrap heavy queries in try-catch to prevent error boundary on transient DB failures
- Reusable pagination component extracted to src/components/shared/pagination.tsx
- Old /admin/users and /admin/mentors routes redirect to /admin/members
- Prisma migration for all schema additions (additive, no data loss)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 16:58:29 +01:00
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.findMany({
|
|
|
|
|
where: { country: { not: null } },
|
|
|
|
|
select: { country: true },
|
|
|
|
|
distinct: ['country'],
|
|
|
|
|
orderBy: { country: 'asc' },
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.groupBy({
|
|
|
|
|
by: ['competitionCategory'],
|
|
|
|
|
where: { competitionCategory: { not: null } },
|
|
|
|
|
_count: true,
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.groupBy({
|
|
|
|
|
by: ['oceanIssue'],
|
|
|
|
|
where: { oceanIssue: { not: null } },
|
|
|
|
|
_count: true,
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
rounds,
|
|
|
|
|
countries: countries.map((c) => c.country).filter(Boolean) as string[],
|
|
|
|
|
categories: categories.map((c) => ({
|
|
|
|
|
value: c.competitionCategory!,
|
|
|
|
|
count: c._count,
|
|
|
|
|
})),
|
|
|
|
|
issues: issues.map((i) => ({
|
|
|
|
|
value: i.oceanIssue!,
|
|
|
|
|
count: i._count,
|
|
|
|
|
})),
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
/**
|
|
|
|
|
* Get a single project with details
|
|
|
|
|
*/
|
|
|
|
|
get: protectedProcedure
|
|
|
|
|
.input(z.object({ id: z.string() }))
|
|
|
|
|
.query(async ({ ctx, input }) => {
|
|
|
|
|
const project = await ctx.prisma.project.findUniqueOrThrow({
|
|
|
|
|
where: { id: input.id },
|
|
|
|
|
include: {
|
|
|
|
|
files: true,
|
2026-02-04 14:15:06 +01:00
|
|
|
round: true,
|
2026-01-30 13:41:32 +01:00
|
|
|
teamMembers: {
|
|
|
|
|
include: {
|
|
|
|
|
user: {
|
2026-02-02 13:19:28 +01:00
|
|
|
select: { id: true, name: true, email: true, profileImageKey: true, profileImageProvider: true },
|
2026-01-30 13:41:32 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
orderBy: { joinedAt: 'asc' },
|
|
|
|
|
},
|
|
|
|
|
mentorAssignment: {
|
|
|
|
|
include: {
|
|
|
|
|
mentor: {
|
2026-02-02 13:19:28 +01:00
|
|
|
select: { id: true, name: true, email: true, expertiseTags: true, profileImageKey: true, profileImageProvider: true },
|
2026-01-30 13:41:32 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-02-05 13:18:45 +01:00
|
|
|
projectTags: {
|
|
|
|
|
include: {
|
|
|
|
|
tag: {
|
|
|
|
|
select: { id: true, name: true, category: true, color: true },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
orderBy: { confidence: 'desc' },
|
|
|
|
|
},
|
2026-01-30 13:41:32 +01:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Check access for jury members
|
|
|
|
|
if (ctx.user.role === 'JURY_MEMBER') {
|
|
|
|
|
const assignment = await ctx.prisma.assignment.findFirst({
|
|
|
|
|
where: {
|
|
|
|
|
projectId: input.id,
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!assignment) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: 'FORBIDDEN',
|
|
|
|
|
message: 'You are not assigned to this project',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 13:19:28 +01:00
|
|
|
// Attach avatar URLs to team members and mentor
|
|
|
|
|
const teamMembersWithAvatars = await Promise.all(
|
|
|
|
|
project.teamMembers.map(async (member) => ({
|
|
|
|
|
...member,
|
|
|
|
|
user: {
|
|
|
|
|
...member.user,
|
|
|
|
|
avatarUrl: await getUserAvatarUrl(member.user.profileImageKey, member.user.profileImageProvider),
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const mentorWithAvatar = project.mentorAssignment
|
|
|
|
|
? {
|
|
|
|
|
...project.mentorAssignment,
|
|
|
|
|
mentor: {
|
|
|
|
|
...project.mentorAssignment.mentor,
|
|
|
|
|
avatarUrl: await getUserAvatarUrl(
|
|
|
|
|
project.mentorAssignment.mentor.profileImageKey,
|
|
|
|
|
project.mentorAssignment.mentor.profileImageProvider
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: null
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...project,
|
|
|
|
|
teamMembers: teamMembersWithAvatars,
|
|
|
|
|
mentorAssignment: mentorWithAvatar,
|
|
|
|
|
}
|
2026-01-30 13:41:32 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a single project (admin only)
|
2026-02-04 14:15:06 +01:00
|
|
|
* Projects belong to a round.
|
2026-01-30 13:41:32 +01:00
|
|
|
*/
|
|
|
|
|
create: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
2026-02-04 14:15:06 +01:00
|
|
|
roundId: z.string(),
|
2026-01-30 13:41:32 +01:00
|
|
|
title: z.string().min(1).max(500),
|
|
|
|
|
teamName: z.string().optional(),
|
|
|
|
|
description: z.string().optional(),
|
|
|
|
|
tags: z.array(z.string()).optional(),
|
|
|
|
|
metadataJson: z.record(z.unknown()).optional(),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2026-02-04 14:15:06 +01:00
|
|
|
const { metadataJson, ...rest } = input
|
2026-02-05 21:09:06 +01:00
|
|
|
const project = await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
|
const created = await tx.project.create({
|
|
|
|
|
data: {
|
|
|
|
|
...rest,
|
|
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
status: 'SUBMITTED',
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-01-30 13:41:32 +01:00
|
|
|
|
2026-02-05 21:09:06 +01:00
|
|
|
await logAudit({
|
|
|
|
|
prisma: tx,
|
2026-01-30 13:41:32 +01:00
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'CREATE',
|
|
|
|
|
entityType: 'Project',
|
2026-02-05 21:09:06 +01:00
|
|
|
entityId: created.id,
|
2026-02-04 14:15:06 +01:00
|
|
|
detailsJson: { title: input.title, roundId: input.roundId },
|
2026-01-30 13:41:32 +01:00
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
2026-02-05 21:09:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return created
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a project (admin only)
|
2026-02-02 22:33:55 +01:00
|
|
|
* Status updates require a roundId context since status is per-round.
|
2026-01-30 13:41:32 +01:00
|
|
|
*/
|
|
|
|
|
update: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
title: z.string().min(1).max(500).optional(),
|
|
|
|
|
teamName: z.string().optional().nullable(),
|
|
|
|
|
description: z.string().optional().nullable(),
|
2026-02-04 16:13:40 +01:00
|
|
|
country: z.string().optional().nullable(), // ISO-2 code or country name (will be normalized)
|
2026-02-02 22:33:55 +01:00
|
|
|
// Status update requires roundId
|
|
|
|
|
roundId: z.string().optional(),
|
2026-01-30 13:41:32 +01:00
|
|
|
status: z
|
|
|
|
|
.enum([
|
|
|
|
|
'SUBMITTED',
|
|
|
|
|
'ELIGIBLE',
|
|
|
|
|
'ASSIGNED',
|
|
|
|
|
'SEMIFINALIST',
|
|
|
|
|
'FINALIST',
|
|
|
|
|
'REJECTED',
|
|
|
|
|
])
|
|
|
|
|
.optional(),
|
|
|
|
|
tags: z.array(z.string()).optional(),
|
|
|
|
|
metadataJson: z.record(z.unknown()).optional(),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2026-02-04 16:13:40 +01:00
|
|
|
const { id, metadataJson, status, roundId, country, ...data } = input
|
|
|
|
|
|
|
|
|
|
// Normalize country to ISO-2 code if provided
|
|
|
|
|
const normalizedCountry = country !== undefined
|
|
|
|
|
? (country === null ? null : normalizeCountryToCode(country))
|
|
|
|
|
: undefined
|
2026-01-30 13:41:32 +01:00
|
|
|
|
|
|
|
|
const project = await ctx.prisma.project.update({
|
|
|
|
|
where: { id },
|
|
|
|
|
data: {
|
|
|
|
|
...data,
|
2026-02-04 14:15:06 +01:00
|
|
|
...(status && { status }),
|
2026-02-04 16:13:40 +01:00
|
|
|
...(normalizedCountry !== undefined && { country: normalizedCountry }),
|
2026-01-30 13:41:32 +01:00
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
Implement 10 platform features: evaluation UX, admin tools, AI summaries, applicant portal
Batch 1 - Quick Wins:
- F1: Evaluation progress indicator with touch tracking in sticky status bar
- F2: Export filtering results as CSV with dynamic AI column flattening
- F3: Observer access to analytics dashboards (8 procedures changed to observerProcedure)
Batch 2 - Jury Experience:
- F4: Countdown timer component with urgency colors + email reminder service with cron endpoint
- F5: Conflict of interest declaration system (dialog, admin management, review workflow)
Batch 3 - Admin & AI Enhancements:
- F6: Bulk status update UI with selection checkboxes, floating toolbar, status history recording
- F7: AI-powered evaluation summary with anonymized data, OpenAI integration, scoring patterns
- F8: Smart assignment improvements (geo diversity penalty, round familiarity bonus, COI blocking)
Batch 4 - Form Flexibility & Applicant Portal:
- F9: Evaluation form flexibility (text, boolean, section_header types, conditional visibility)
- F10: Applicant portal (status timeline, per-round documents, mentor messaging)
Schema: 5 new models (ReminderLog, ConflictOfInterest, EvaluationSummary, ProjectStatusHistory, MentorMessage), ProjectFile extended with roundId + isLate.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 21:58:27 +01:00
|
|
|
// Record status change in history
|
|
|
|
|
if (status) {
|
|
|
|
|
await ctx.prisma.projectStatusHistory.create({
|
|
|
|
|
data: {
|
|
|
|
|
projectId: id,
|
|
|
|
|
status,
|
|
|
|
|
changedBy: ctx.user.id,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
// Send notifications if status changed
|
|
|
|
|
if (status) {
|
|
|
|
|
// Get round details for notification
|
|
|
|
|
const projectWithRound = await ctx.prisma.project.findUnique({
|
|
|
|
|
where: { id },
|
|
|
|
|
include: { round: { select: { name: true, entryNotificationType: true, program: { select: { name: true } } } } },
|
2026-02-02 22:33:55 +01:00
|
|
|
})
|
2026-02-04 00:10:51 +01:00
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
const round = projectWithRound?.round
|
2026-02-04 00:10:51 +01:00
|
|
|
|
|
|
|
|
// Helper to get notification title based on type
|
|
|
|
|
const getNotificationTitle = (type: string): string => {
|
|
|
|
|
const titles: Record<string, string> = {
|
|
|
|
|
ADVANCED_SEMIFINAL: "Congratulations! You're a Semi-Finalist",
|
|
|
|
|
ADVANCED_FINAL: "Amazing News! You're a Finalist",
|
|
|
|
|
NOT_SELECTED: 'Application Status Update',
|
|
|
|
|
WINNER_ANNOUNCEMENT: 'Congratulations! You Won!',
|
|
|
|
|
}
|
|
|
|
|
return titles[type] || 'Project Update'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper to get notification message based on type
|
|
|
|
|
const getNotificationMessage = (type: string, projectName: string): string => {
|
|
|
|
|
const messages: Record<string, (name: string) => string> = {
|
|
|
|
|
ADVANCED_SEMIFINAL: (name) => `Your project "${name}" has advanced to the semi-finals!`,
|
|
|
|
|
ADVANCED_FINAL: (name) => `Your project "${name}" has been selected as a finalist!`,
|
|
|
|
|
NOT_SELECTED: (name) => `We regret to inform you that "${name}" was not selected for the next round.`,
|
|
|
|
|
WINNER_ANNOUNCEMENT: (name) => `Your project "${name}" has been selected as a winner!`,
|
|
|
|
|
}
|
|
|
|
|
return messages[type]?.(projectName) || `Update regarding your project "${projectName}".`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use round's configured notification type, or fall back to status-based defaults
|
|
|
|
|
if (round?.entryNotificationType) {
|
|
|
|
|
await notifyProjectTeam(id, {
|
|
|
|
|
type: round.entryNotificationType,
|
|
|
|
|
title: getNotificationTitle(round.entryNotificationType),
|
|
|
|
|
message: getNotificationMessage(round.entryNotificationType, project.title),
|
|
|
|
|
linkUrl: `/team/projects/${id}`,
|
|
|
|
|
linkLabel: 'View Project',
|
|
|
|
|
priority: round.entryNotificationType === 'NOT_SELECTED' ? 'normal' : 'high',
|
|
|
|
|
metadata: {
|
|
|
|
|
projectName: project.title,
|
|
|
|
|
roundName: round.name,
|
|
|
|
|
programName: round.program?.name,
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-02-04 14:15:06 +01:00
|
|
|
} else if (round) {
|
2026-02-04 00:10:51 +01:00
|
|
|
// Fall back to hardcoded status-based notifications
|
|
|
|
|
const notificationConfig: Record<
|
|
|
|
|
string,
|
|
|
|
|
{ type: string; title: string; message: string }
|
|
|
|
|
> = {
|
|
|
|
|
SEMIFINALIST: {
|
|
|
|
|
type: NotificationTypes.ADVANCED_SEMIFINAL,
|
|
|
|
|
title: "Congratulations! You're a Semi-Finalist",
|
|
|
|
|
message: `Your project "${project.title}" has advanced to the semi-finals!`,
|
|
|
|
|
},
|
|
|
|
|
FINALIST: {
|
|
|
|
|
type: NotificationTypes.ADVANCED_FINAL,
|
|
|
|
|
title: "Amazing News! You're a Finalist",
|
|
|
|
|
message: `Your project "${project.title}" has been selected as a finalist!`,
|
|
|
|
|
},
|
|
|
|
|
REJECTED: {
|
|
|
|
|
type: NotificationTypes.NOT_SELECTED,
|
|
|
|
|
title: 'Application Status Update',
|
|
|
|
|
message: `We regret to inform you that "${project.title}" was not selected for the next round.`,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const config = notificationConfig[status]
|
|
|
|
|
if (config) {
|
|
|
|
|
await notifyProjectTeam(id, {
|
|
|
|
|
type: config.type,
|
|
|
|
|
title: config.title,
|
|
|
|
|
message: config.message,
|
|
|
|
|
linkUrl: `/team/projects/${id}`,
|
|
|
|
|
linkLabel: 'View Project',
|
|
|
|
|
priority: status === 'REJECTED' ? 'normal' : 'high',
|
|
|
|
|
metadata: {
|
|
|
|
|
projectName: project.title,
|
|
|
|
|
roundName: round?.name,
|
|
|
|
|
programName: round?.program?.name,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
// Audit log
|
2026-02-05 21:09:06 +01:00
|
|
|
await logAudit({
|
|
|
|
|
prisma: ctx.prisma,
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'UPDATE',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
entityId: id,
|
|
|
|
|
detailsJson: { ...data, status, metadataJson } as Record<string, unknown>,
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a project (admin only)
|
|
|
|
|
*/
|
|
|
|
|
delete: adminProcedure
|
|
|
|
|
.input(z.object({ id: z.string() }))
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2026-02-05 21:09:06 +01:00
|
|
|
const project = await ctx.prisma.$transaction(async (tx) => {
|
|
|
|
|
const target = await tx.project.findUniqueOrThrow({
|
|
|
|
|
where: { id: input.id },
|
|
|
|
|
select: { id: true, title: true },
|
|
|
|
|
})
|
2026-01-30 13:41:32 +01:00
|
|
|
|
2026-02-05 21:09:06 +01:00
|
|
|
await logAudit({
|
|
|
|
|
prisma: tx,
|
2026-01-30 13:41:32 +01:00
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'DELETE',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
entityId: input.id,
|
2026-02-05 21:09:06 +01:00
|
|
|
detailsJson: { title: target.title },
|
2026-01-30 13:41:32 +01:00
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
2026-02-05 21:09:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return tx.project.delete({
|
|
|
|
|
where: { id: input.id },
|
|
|
|
|
})
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import projects from CSV data (admin only)
|
2026-02-02 22:33:55 +01:00
|
|
|
* Projects belong to a program. Optionally assign to a round.
|
2026-01-30 13:41:32 +01:00
|
|
|
*/
|
|
|
|
|
importCSV: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
2026-02-02 22:33:55 +01:00
|
|
|
programId: z.string(),
|
|
|
|
|
roundId: z.string().optional(),
|
2026-01-30 13:41:32 +01:00
|
|
|
projects: z.array(
|
|
|
|
|
z.object({
|
|
|
|
|
title: z.string().min(1),
|
|
|
|
|
teamName: z.string().optional(),
|
|
|
|
|
description: z.string().optional(),
|
|
|
|
|
tags: z.array(z.string()).optional(),
|
|
|
|
|
metadataJson: z.record(z.unknown()).optional(),
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2026-02-02 22:33:55 +01:00
|
|
|
// Verify program exists
|
|
|
|
|
await ctx.prisma.program.findUniqueOrThrow({
|
|
|
|
|
where: { id: input.programId },
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
2026-02-02 22:33:55 +01:00
|
|
|
// Verify round exists and belongs to program if provided
|
|
|
|
|
if (input.roundId) {
|
|
|
|
|
const round = await ctx.prisma.round.findUniqueOrThrow({
|
|
|
|
|
where: { id: input.roundId },
|
|
|
|
|
})
|
|
|
|
|
if (round.programId !== input.programId) {
|
|
|
|
|
throw new TRPCError({
|
|
|
|
|
code: 'BAD_REQUEST',
|
|
|
|
|
message: 'Round does not belong to the selected program',
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create projects in a transaction
|
|
|
|
|
const result = await ctx.prisma.$transaction(async (tx) => {
|
2026-02-04 14:15:06 +01:00
|
|
|
// Create all projects with roundId
|
2026-02-02 22:33:55 +01:00
|
|
|
const projectData = input.projects.map((p) => {
|
2026-01-30 13:41:32 +01:00
|
|
|
const { metadataJson, ...rest } = p
|
|
|
|
|
return {
|
|
|
|
|
...rest,
|
2026-02-04 14:15:06 +01:00
|
|
|
roundId: input.roundId!,
|
|
|
|
|
status: 'SUBMITTED' as const,
|
2026-01-30 13:41:32 +01:00
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
}
|
2026-02-02 22:33:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const created = await tx.project.createManyAndReturn({
|
|
|
|
|
data: projectData,
|
|
|
|
|
select: { id: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return { imported: created.length }
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
2026-02-05 21:09:06 +01:00
|
|
|
await logAudit({
|
|
|
|
|
prisma: ctx.prisma,
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'IMPORT',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
detailsJson: { programId: input.programId, roundId: input.roundId, count: result.imported },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
2026-02-02 22:33:55 +01:00
|
|
|
return result
|
2026-01-30 13:41:32 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all unique tags used in projects
|
|
|
|
|
*/
|
|
|
|
|
getTags: protectedProcedure
|
2026-02-02 22:33:55 +01:00
|
|
|
.input(z.object({
|
|
|
|
|
roundId: z.string().optional(),
|
|
|
|
|
programId: z.string().optional(),
|
|
|
|
|
}))
|
2026-01-30 13:41:32 +01:00
|
|
|
.query(async ({ ctx, input }) => {
|
2026-02-02 22:33:55 +01:00
|
|
|
const where: Record<string, unknown> = {}
|
2026-02-04 14:15:06 +01:00
|
|
|
if (input.programId) where.round = { programId: input.programId }
|
|
|
|
|
if (input.roundId) where.roundId = input.roundId
|
2026-02-02 22:33:55 +01:00
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
const projects = await ctx.prisma.project.findMany({
|
2026-02-02 22:33:55 +01:00
|
|
|
where: Object.keys(where).length > 0 ? where : undefined,
|
2026-01-30 13:41:32 +01:00
|
|
|
select: { tags: true },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const allTags = projects.flatMap((p) => p.tags)
|
|
|
|
|
const uniqueTags = [...new Set(allTags)].sort()
|
|
|
|
|
|
|
|
|
|
return uniqueTags
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update project status in bulk (admin only)
|
2026-02-02 22:33:55 +01:00
|
|
|
* Status is per-round, so roundId is required.
|
2026-01-30 13:41:32 +01:00
|
|
|
*/
|
|
|
|
|
bulkUpdateStatus: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
ids: z.array(z.string()),
|
2026-02-02 22:33:55 +01:00
|
|
|
roundId: z.string(),
|
2026-01-30 13:41:32 +01:00
|
|
|
status: z.enum([
|
|
|
|
|
'SUBMITTED',
|
|
|
|
|
'ELIGIBLE',
|
|
|
|
|
'ASSIGNED',
|
|
|
|
|
'SEMIFINALIST',
|
|
|
|
|
'FINALIST',
|
|
|
|
|
'REJECTED',
|
|
|
|
|
]),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2026-02-05 21:09:06 +01:00
|
|
|
// Fetch matching projects BEFORE update so notifications match actually-updated records
|
|
|
|
|
const [projects, round] = await Promise.all([
|
|
|
|
|
ctx.prisma.project.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
id: { in: input.ids },
|
|
|
|
|
roundId: input.roundId,
|
|
|
|
|
},
|
|
|
|
|
select: { id: true, title: true },
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.round.findUnique({
|
|
|
|
|
where: { id: input.roundId },
|
|
|
|
|
select: { name: true, entryNotificationType: true, program: { select: { name: true } } },
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const matchingIds = projects.map((p) => p.id)
|
|
|
|
|
|
2026-02-04 14:15:06 +01:00
|
|
|
const updated = await ctx.prisma.project.updateMany({
|
2026-02-02 22:33:55 +01:00
|
|
|
where: {
|
2026-02-05 21:09:06 +01:00
|
|
|
id: { in: matchingIds },
|
2026-02-02 22:33:55 +01:00
|
|
|
roundId: input.roundId,
|
|
|
|
|
},
|
2026-01-30 13:41:32 +01:00
|
|
|
data: { status: input.status },
|
|
|
|
|
})
|
|
|
|
|
|
Implement 10 platform features: evaluation UX, admin tools, AI summaries, applicant portal
Batch 1 - Quick Wins:
- F1: Evaluation progress indicator with touch tracking in sticky status bar
- F2: Export filtering results as CSV with dynamic AI column flattening
- F3: Observer access to analytics dashboards (8 procedures changed to observerProcedure)
Batch 2 - Jury Experience:
- F4: Countdown timer component with urgency colors + email reminder service with cron endpoint
- F5: Conflict of interest declaration system (dialog, admin management, review workflow)
Batch 3 - Admin & AI Enhancements:
- F6: Bulk status update UI with selection checkboxes, floating toolbar, status history recording
- F7: AI-powered evaluation summary with anonymized data, OpenAI integration, scoring patterns
- F8: Smart assignment improvements (geo diversity penalty, round familiarity bonus, COI blocking)
Batch 4 - Form Flexibility & Applicant Portal:
- F9: Evaluation form flexibility (text, boolean, section_header types, conditional visibility)
- F10: Applicant portal (status timeline, per-round documents, mentor messaging)
Schema: 5 new models (ReminderLog, ConflictOfInterest, EvaluationSummary, ProjectStatusHistory, MentorMessage), ProjectFile extended with roundId + isLate.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 21:58:27 +01:00
|
|
|
// Record status change in history for each project
|
|
|
|
|
if (matchingIds.length > 0) {
|
|
|
|
|
await ctx.prisma.projectStatusHistory.createMany({
|
|
|
|
|
data: matchingIds.map((projectId) => ({
|
|
|
|
|
projectId,
|
|
|
|
|
status: input.status,
|
|
|
|
|
changedBy: ctx.user.id,
|
|
|
|
|
})),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
// Audit log
|
2026-02-05 21:09:06 +01:00
|
|
|
await logAudit({
|
|
|
|
|
prisma: ctx.prisma,
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'BULK_UPDATE_STATUS',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
detailsJson: { ids: matchingIds, roundId: input.roundId, status: input.status, count: updated.count },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|
|
|
|
|
|
2026-02-04 00:10:51 +01:00
|
|
|
// Helper to get notification title based on type
|
|
|
|
|
const getNotificationTitle = (type: string): string => {
|
|
|
|
|
const titles: Record<string, string> = {
|
|
|
|
|
ADVANCED_SEMIFINAL: "Congratulations! You're a Semi-Finalist",
|
|
|
|
|
ADVANCED_FINAL: "Amazing News! You're a Finalist",
|
|
|
|
|
NOT_SELECTED: 'Application Status Update',
|
|
|
|
|
WINNER_ANNOUNCEMENT: 'Congratulations! You Won!',
|
|
|
|
|
}
|
|
|
|
|
return titles[type] || 'Project Update'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper to get notification message based on type
|
|
|
|
|
const getNotificationMessage = (type: string, projectName: string): string => {
|
|
|
|
|
const messages: Record<string, (name: string) => string> = {
|
|
|
|
|
ADVANCED_SEMIFINAL: (name) => `Your project "${name}" has advanced to the semi-finals!`,
|
|
|
|
|
ADVANCED_FINAL: (name) => `Your project "${name}" has been selected as a finalist!`,
|
|
|
|
|
NOT_SELECTED: (name) => `We regret to inform you that "${name}" was not selected for the next round.`,
|
|
|
|
|
WINNER_ANNOUNCEMENT: (name) => `Your project "${name}" has been selected as a winner!`,
|
|
|
|
|
}
|
|
|
|
|
return messages[type]?.(projectName) || `Update regarding your project "${projectName}".`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Notify project teams based on round's configured notification or status-based fallback
|
|
|
|
|
if (projects.length > 0) {
|
|
|
|
|
if (round?.entryNotificationType) {
|
|
|
|
|
// Use round's configured notification type
|
|
|
|
|
for (const project of projects) {
|
|
|
|
|
await notifyProjectTeam(project.id, {
|
|
|
|
|
type: round.entryNotificationType,
|
|
|
|
|
title: getNotificationTitle(round.entryNotificationType),
|
|
|
|
|
message: getNotificationMessage(round.entryNotificationType, project.title),
|
|
|
|
|
linkUrl: `/team/projects/${project.id}`,
|
|
|
|
|
linkLabel: 'View Project',
|
|
|
|
|
priority: round.entryNotificationType === 'NOT_SELECTED' ? 'normal' : 'high',
|
|
|
|
|
metadata: {
|
|
|
|
|
projectName: project.title,
|
|
|
|
|
roundName: round.name,
|
|
|
|
|
programName: round.program?.name,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Fall back to hardcoded status-based notifications
|
|
|
|
|
const notificationConfig: Record<
|
|
|
|
|
string,
|
|
|
|
|
{ type: string; titleFn: (name: string) => string; messageFn: (name: string) => string }
|
|
|
|
|
> = {
|
|
|
|
|
SEMIFINALIST: {
|
|
|
|
|
type: NotificationTypes.ADVANCED_SEMIFINAL,
|
|
|
|
|
titleFn: () => "Congratulations! You're a Semi-Finalist",
|
|
|
|
|
messageFn: (name) => `Your project "${name}" has advanced to the semi-finals!`,
|
|
|
|
|
},
|
|
|
|
|
FINALIST: {
|
|
|
|
|
type: NotificationTypes.ADVANCED_FINAL,
|
|
|
|
|
titleFn: () => "Amazing News! You're a Finalist",
|
|
|
|
|
messageFn: (name) => `Your project "${name}" has been selected as a finalist!`,
|
|
|
|
|
},
|
|
|
|
|
REJECTED: {
|
|
|
|
|
type: NotificationTypes.NOT_SELECTED,
|
|
|
|
|
titleFn: () => 'Application Status Update',
|
|
|
|
|
messageFn: (name) =>
|
|
|
|
|
`We regret to inform you that "${name}" was not selected for the next round.`,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const config = notificationConfig[input.status]
|
|
|
|
|
if (config) {
|
|
|
|
|
for (const project of projects) {
|
|
|
|
|
await notifyProjectTeam(project.id, {
|
|
|
|
|
type: config.type,
|
|
|
|
|
title: config.titleFn(project.title),
|
|
|
|
|
message: config.messageFn(project.title),
|
|
|
|
|
linkUrl: `/team/projects/${project.id}`,
|
|
|
|
|
linkLabel: 'View Project',
|
|
|
|
|
priority: input.status === 'REJECTED' ? 'normal' : 'high',
|
|
|
|
|
metadata: {
|
|
|
|
|
projectName: project.title,
|
|
|
|
|
roundName: round?.name,
|
|
|
|
|
programName: round?.program?.name,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 13:41:32 +01:00
|
|
|
return { updated: updated.count }
|
|
|
|
|
}),
|
2026-02-02 22:33:55 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List projects in a program's pool (not assigned to any round)
|
|
|
|
|
*/
|
|
|
|
|
listPool: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
programId: z.string(),
|
|
|
|
|
search: z.string().optional(),
|
|
|
|
|
page: z.number().int().min(1).default(1),
|
|
|
|
|
perPage: z.number().int().min(1).max(100).default(50),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.query(async ({ ctx, input }) => {
|
|
|
|
|
const { programId, search, page, perPage } = input
|
|
|
|
|
const skip = (page - 1) * perPage
|
|
|
|
|
|
|
|
|
|
const where: Record<string, unknown> = {
|
2026-02-04 14:15:06 +01:00
|
|
|
round: { programId },
|
|
|
|
|
roundId: null,
|
2026-02-02 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (search) {
|
|
|
|
|
where.OR = [
|
|
|
|
|
{ title: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
{ teamName: { contains: search, mode: 'insensitive' } },
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const [projects, total] = await Promise.all([
|
|
|
|
|
ctx.prisma.project.findMany({
|
|
|
|
|
where,
|
|
|
|
|
skip,
|
|
|
|
|
take: perPage,
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
select: {
|
|
|
|
|
id: true,
|
|
|
|
|
title: true,
|
|
|
|
|
teamName: true,
|
|
|
|
|
country: true,
|
|
|
|
|
competitionCategory: true,
|
|
|
|
|
createdAt: true,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
ctx.prisma.project.count({ where }),
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return { projects, total, page, perPage, totalPages: Math.ceil(total / perPage) }
|
|
|
|
|
}),
|
2026-01-30 13:41:32 +01:00
|
|
|
})
|