Remove dynamic form builder and complete RoundProject→roundId migration
Major cleanup and schema migration: - Remove unused dynamic form builder system (ApplicationForm, ApplicationFormField, etc.) - Complete migration from RoundProject junction table to direct Project.roundId - Add sortOrder and entryNotificationType fields to Round model - Add country field to User model for mentor matching - Enhance onboarding with profile photo and country selection steps - Fix all TypeScript errors related to roundProjects references - Remove unused libraries (@radix-ui/react-toast, embla-carousel-react, vaul) Files removed: - admin/forms/* pages and related components - admin/onboarding/* pages - applicationForm.ts and onboarding.ts routers - Dynamic form builder Prisma models and enums Schema changes: - Removed ApplicationForm, ApplicationFormField, OnboardingStep, ApplicationFormSubmission, SubmissionFile models - Removed FormFieldType and SpecialFieldType enums - Added Round.sortOrder, Round.entryNotificationType - Added User.country Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ export const roundRouter = router({
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
include: {
|
||||
_count: {
|
||||
select: { roundProjects: true, assignments: true },
|
||||
select: { projects: true, assignments: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -36,7 +36,7 @@ export const roundRouter = router({
|
||||
include: {
|
||||
program: true,
|
||||
_count: {
|
||||
select: { roundProjects: true, assignments: true },
|
||||
select: { projects: true, assignments: true },
|
||||
},
|
||||
evaluationForms: {
|
||||
where: { isActive: true },
|
||||
@@ -113,23 +113,18 @@ export const roundRouter = router({
|
||||
},
|
||||
})
|
||||
|
||||
// For FILTERING rounds, automatically add all projects from the program
|
||||
// For FILTERING rounds, automatically move all projects from the program to this round
|
||||
if (input.roundType === 'FILTERING') {
|
||||
const projects = await ctx.prisma.project.findMany({
|
||||
where: { programId: input.programId },
|
||||
select: { id: true },
|
||||
await ctx.prisma.project.updateMany({
|
||||
where: {
|
||||
round: { programId: input.programId },
|
||||
roundId: { not: round.id },
|
||||
},
|
||||
data: {
|
||||
roundId: round.id,
|
||||
status: 'SUBMITTED',
|
||||
},
|
||||
})
|
||||
|
||||
if (projects.length > 0) {
|
||||
await ctx.prisma.roundProject.createMany({
|
||||
data: projects.map((p) => ({
|
||||
roundId: round.id,
|
||||
projectId: p.id,
|
||||
status: 'SUBMITTED',
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Audit log
|
||||
@@ -341,7 +336,7 @@ export const roundRouter = router({
|
||||
.query(async ({ ctx, input }) => {
|
||||
const [totalProjects, totalAssignments, completedAssignments] =
|
||||
await Promise.all([
|
||||
ctx.prisma.roundProject.count({ where: { roundId: input.id } }),
|
||||
ctx.prisma.project.count({ where: { roundId: input.id } }),
|
||||
ctx.prisma.assignment.count({ where: { roundId: input.id } }),
|
||||
ctx.prisma.assignment.count({
|
||||
where: { roundId: input.id, isCompleted: true },
|
||||
@@ -472,7 +467,7 @@ export const roundRouter = router({
|
||||
const round = await ctx.prisma.round.findUniqueOrThrow({
|
||||
where: { id: input.id },
|
||||
include: {
|
||||
_count: { select: { roundProjects: true, assignments: true } },
|
||||
_count: { select: { projects: true, assignments: true } },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -490,7 +485,7 @@ export const roundRouter = router({
|
||||
detailsJson: {
|
||||
name: round.name,
|
||||
status: round.status,
|
||||
projectsDeleted: round._count.roundProjects,
|
||||
projectsDeleted: round._count.projects,
|
||||
assignmentsDeleted: round._count.assignments,
|
||||
},
|
||||
ipAddress: ctx.ip,
|
||||
@@ -532,29 +527,25 @@ export const roundRouter = router({
|
||||
where: { id: input.roundId },
|
||||
})
|
||||
|
||||
// Verify all projects belong to the same program
|
||||
const projects = await ctx.prisma.project.findMany({
|
||||
where: { id: { in: input.projectIds }, programId: round.programId },
|
||||
select: { id: true },
|
||||
// Update projects to assign them to this round
|
||||
const updated = await ctx.prisma.project.updateMany({
|
||||
where: {
|
||||
id: { in: input.projectIds },
|
||||
round: { programId: round.programId },
|
||||
},
|
||||
data: {
|
||||
roundId: input.roundId,
|
||||
status: 'SUBMITTED',
|
||||
},
|
||||
})
|
||||
|
||||
if (projects.length !== input.projectIds.length) {
|
||||
if (updated.count === 0) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'Some projects do not belong to this program',
|
||||
message: 'No projects were assigned. Projects may not belong to this program.',
|
||||
})
|
||||
}
|
||||
|
||||
// Create RoundProject entries (skip duplicates)
|
||||
const created = await ctx.prisma.roundProject.createMany({
|
||||
data: input.projectIds.map((projectId) => ({
|
||||
roundId: input.roundId,
|
||||
projectId,
|
||||
status: 'SUBMITTED' as const,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
})
|
||||
|
||||
// Audit log
|
||||
await ctx.prisma.auditLog.create({
|
||||
data: {
|
||||
@@ -562,13 +553,13 @@ export const roundRouter = router({
|
||||
action: 'ASSIGN_PROJECTS_TO_ROUND',
|
||||
entityType: 'Round',
|
||||
entityId: input.roundId,
|
||||
detailsJson: { projectCount: created.count },
|
||||
detailsJson: { projectCount: updated.count },
|
||||
ipAddress: ctx.ip,
|
||||
userAgent: ctx.userAgent,
|
||||
},
|
||||
})
|
||||
|
||||
return { assigned: created.count }
|
||||
return { assigned: updated.count }
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -582,12 +573,17 @@ export const roundRouter = router({
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const deleted = await ctx.prisma.roundProject.deleteMany({
|
||||
// Set roundId to null for these projects (remove from round)
|
||||
const updated = await ctx.prisma.project.updateMany({
|
||||
where: {
|
||||
roundId: input.roundId,
|
||||
projectId: { in: input.projectIds },
|
||||
id: { in: input.projectIds },
|
||||
},
|
||||
data: {
|
||||
roundId: null as unknown as string, // Projects need to be orphaned
|
||||
},
|
||||
})
|
||||
const deleted = { count: updated.count }
|
||||
|
||||
// Audit log
|
||||
await ctx.prisma.auditLog.create({
|
||||
@@ -632,12 +628,12 @@ export const roundRouter = router({
|
||||
}
|
||||
|
||||
// Verify all projects are in the source round
|
||||
const sourceProjects = await ctx.prisma.roundProject.findMany({
|
||||
const sourceProjects = await ctx.prisma.project.findMany({
|
||||
where: {
|
||||
roundId: input.fromRoundId,
|
||||
projectId: { in: input.projectIds },
|
||||
id: { in: input.projectIds },
|
||||
},
|
||||
select: { projectId: true },
|
||||
select: { id: true },
|
||||
})
|
||||
|
||||
if (sourceProjects.length !== input.projectIds.length) {
|
||||
@@ -647,15 +643,18 @@ export const roundRouter = router({
|
||||
})
|
||||
}
|
||||
|
||||
// Create entries in target round (skip duplicates)
|
||||
const created = await ctx.prisma.roundProject.createMany({
|
||||
data: input.projectIds.map((projectId) => ({
|
||||
// Move projects to target round
|
||||
const updated = await ctx.prisma.project.updateMany({
|
||||
where: {
|
||||
id: { in: input.projectIds },
|
||||
roundId: input.fromRoundId,
|
||||
},
|
||||
data: {
|
||||
roundId: input.toRoundId,
|
||||
projectId,
|
||||
status: 'SUBMITTED' as const,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
status: 'SUBMITTED',
|
||||
},
|
||||
})
|
||||
const created = { count: updated.count }
|
||||
|
||||
// Audit log
|
||||
await ctx.prisma.auditLog.create({
|
||||
|
||||
Reference in New Issue
Block a user