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-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({
|
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-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),
|
|
|
|
|
perPage: z.number().int().min(1).max(100).default(20),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.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 {
|
|
|
|
|
roundId, status, statuses, search, tags,
|
|
|
|
|
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
|
|
|
|
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 (roundId) where.roundId = roundId
|
|
|
|
|
if (statuses && statuses.length > 0) {
|
|
|
|
|
where.status = { in: statuses }
|
|
|
|
|
} else if (status) {
|
|
|
|
|
where.status = status
|
|
|
|
|
}
|
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') {
|
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 hasAssignments filter is already set, combine with jury filter
|
2026-01-30 13:41:32 +01:00
|
|
|
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: {
|
|
|
|
|
files: true,
|
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
|
|
|
round: {
|
|
|
|
|
select: { id: true, name: true, program: { select: { name: true } } },
|
|
|
|
|
},
|
2026-01-30 13:41:32 +01:00
|
|
|
_count: { select: { assignments: true } },
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
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({
|
|
|
|
|
select: { id: true, name: true, program: { select: { name: true } } },
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
}),
|
|
|
|
|
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,
|
|
|
|
|
round: true,
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
*/
|
|
|
|
|
create: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
roundId: z.string(),
|
|
|
|
|
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 }) => {
|
|
|
|
|
const { metadataJson, ...rest } = input
|
|
|
|
|
const project = await ctx.prisma.project.create({
|
|
|
|
|
data: {
|
|
|
|
|
...rest,
|
|
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
|
|
|
|
await ctx.prisma.auditLog.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'CREATE',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
entityId: project.id,
|
|
|
|
|
detailsJson: { title: input.title, roundId: input.roundId },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a project (admin only)
|
|
|
|
|
*/
|
|
|
|
|
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(),
|
|
|
|
|
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 }) => {
|
|
|
|
|
const { id, metadataJson, ...data } = input
|
|
|
|
|
|
|
|
|
|
const project = await ctx.prisma.project.update({
|
|
|
|
|
where: { id },
|
|
|
|
|
data: {
|
|
|
|
|
...data,
|
|
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
|
|
|
|
await ctx.prisma.auditLog.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'UPDATE',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
entityId: id,
|
|
|
|
|
detailsJson: { ...data, metadataJson } as Prisma.InputJsonValue,
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a project (admin only)
|
|
|
|
|
*/
|
|
|
|
|
delete: adminProcedure
|
|
|
|
|
.input(z.object({ id: z.string() }))
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
|
|
|
|
const project = await ctx.prisma.project.delete({
|
|
|
|
|
where: { id: input.id },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
|
|
|
|
await ctx.prisma.auditLog.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'DELETE',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
entityId: input.id,
|
|
|
|
|
detailsJson: { title: project.title },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return project
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import projects from CSV data (admin only)
|
|
|
|
|
*/
|
|
|
|
|
importCSV: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
roundId: z.string(),
|
|
|
|
|
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 }) => {
|
|
|
|
|
// Verify round exists
|
|
|
|
|
await ctx.prisma.round.findUniqueOrThrow({
|
|
|
|
|
where: { id: input.roundId },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const created = await ctx.prisma.project.createMany({
|
|
|
|
|
data: input.projects.map((p) => {
|
|
|
|
|
const { metadataJson, ...rest } = p
|
|
|
|
|
return {
|
|
|
|
|
...rest,
|
|
|
|
|
roundId: input.roundId,
|
|
|
|
|
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
|
|
|
|
await ctx.prisma.auditLog.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'IMPORT',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
detailsJson: { roundId: input.roundId, count: created.count },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return { imported: created.count }
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all unique tags used in projects
|
|
|
|
|
*/
|
|
|
|
|
getTags: protectedProcedure
|
|
|
|
|
.input(z.object({ roundId: z.string().optional() }))
|
|
|
|
|
.query(async ({ ctx, input }) => {
|
|
|
|
|
const projects = await ctx.prisma.project.findMany({
|
|
|
|
|
where: input.roundId ? { roundId: input.roundId } : undefined,
|
|
|
|
|
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)
|
|
|
|
|
*/
|
|
|
|
|
bulkUpdateStatus: adminProcedure
|
|
|
|
|
.input(
|
|
|
|
|
z.object({
|
|
|
|
|
ids: z.array(z.string()),
|
|
|
|
|
status: z.enum([
|
|
|
|
|
'SUBMITTED',
|
|
|
|
|
'ELIGIBLE',
|
|
|
|
|
'ASSIGNED',
|
|
|
|
|
'SEMIFINALIST',
|
|
|
|
|
'FINALIST',
|
|
|
|
|
'REJECTED',
|
|
|
|
|
]),
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
|
|
|
|
const updated = await ctx.prisma.project.updateMany({
|
|
|
|
|
where: { id: { in: input.ids } },
|
|
|
|
|
data: { status: input.status },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Audit log
|
|
|
|
|
await ctx.prisma.auditLog.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: ctx.user.id,
|
|
|
|
|
action: 'BULK_UPDATE_STATUS',
|
|
|
|
|
entityType: 'Project',
|
|
|
|
|
detailsJson: { ids: input.ids, status: input.status },
|
|
|
|
|
ipAddress: ctx.ip,
|
|
|
|
|
userAgent: ctx.userAgent,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return { updated: updated.count }
|
|
|
|
|
}),
|
|
|
|
|
})
|