Decouple projects from rounds with RoundProject join table
Projects now exist at the program level instead of being locked to a single round. A new RoundProject join table enables many-to-many relationships with per-round status tracking. Rounds have sortOrder for configurable progression paths. - Add RoundProject model, programId on Project, sortOrder on Round - Migration preserves existing data (roundId -> RoundProject entries) - Update all routers to query through RoundProject join - Add assign/remove/advance/reorder round endpoints - Add Assign, Advance, Remove Projects dialogs on round detail page - Add round reorder controls (up/down arrows) on rounds list - Show all rounds on project detail page Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -62,7 +62,7 @@ export const applicantRouter = router({
|
||||
|
||||
const project = await ctx.prisma.project.findFirst({
|
||||
where: {
|
||||
roundId: input.roundId,
|
||||
roundProjects: { some: { roundId: input.roundId } },
|
||||
OR: [
|
||||
{ submittedByUserId: ctx.user.id },
|
||||
{
|
||||
@@ -74,9 +74,14 @@ export const applicantRouter = router({
|
||||
},
|
||||
include: {
|
||||
files: true,
|
||||
round: {
|
||||
roundProjects: {
|
||||
where: { roundId: input.roundId },
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
round: {
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
teamMembers: {
|
||||
@@ -171,26 +176,47 @@ export const applicantRouter = router({
|
||||
...data,
|
||||
metadataJson: metadataJson as unknown ?? undefined,
|
||||
submittedAt: submit && !existing.submittedAt ? now : existing.submittedAt,
|
||||
status: submit ? 'SUBMITTED' : existing.status,
|
||||
},
|
||||
})
|
||||
|
||||
// Update RoundProject status if submitting
|
||||
if (submit) {
|
||||
await ctx.prisma.roundProject.updateMany({
|
||||
where: { projectId: projectId },
|
||||
data: { status: 'SUBMITTED' },
|
||||
})
|
||||
}
|
||||
|
||||
return project
|
||||
} else {
|
||||
// Create new
|
||||
// Get the round to find the programId
|
||||
const roundForCreate = await ctx.prisma.round.findUniqueOrThrow({
|
||||
where: { id: roundId },
|
||||
select: { programId: true },
|
||||
})
|
||||
|
||||
// Create new project
|
||||
const project = await ctx.prisma.project.create({
|
||||
data: {
|
||||
roundId,
|
||||
programId: roundForCreate.programId,
|
||||
...data,
|
||||
metadataJson: metadataJson as unknown ?? undefined,
|
||||
submittedByUserId: ctx.user.id,
|
||||
submittedByEmail: ctx.user.email,
|
||||
submissionSource: 'MANUAL',
|
||||
status: 'SUBMITTED',
|
||||
submittedAt: submit ? now : null,
|
||||
},
|
||||
})
|
||||
|
||||
// Create RoundProject entry
|
||||
await ctx.prisma.roundProject.create({
|
||||
data: {
|
||||
roundId,
|
||||
projectId: project.id,
|
||||
status: 'SUBMITTED',
|
||||
},
|
||||
})
|
||||
|
||||
// Audit log
|
||||
await ctx.prisma.auditLog.create({
|
||||
data: {
|
||||
@@ -386,10 +412,15 @@ export const applicantRouter = router({
|
||||
],
|
||||
},
|
||||
include: {
|
||||
round: {
|
||||
roundProjects: {
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
round: {
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { addedAt: 'desc' },
|
||||
},
|
||||
files: true,
|
||||
teamMembers: {
|
||||
@@ -409,6 +440,10 @@ export const applicantRouter = router({
|
||||
})
|
||||
}
|
||||
|
||||
// Get the latest round project status
|
||||
const latestRoundProject = project.roundProjects[0]
|
||||
const currentStatus = latestRoundProject?.status ?? 'SUBMITTED'
|
||||
|
||||
// Build timeline
|
||||
const timeline = [
|
||||
{
|
||||
@@ -426,27 +461,27 @@ export const applicantRouter = router({
|
||||
{
|
||||
status: 'UNDER_REVIEW',
|
||||
label: 'Under Review',
|
||||
date: project.status === 'SUBMITTED' && project.submittedAt ? project.submittedAt : null,
|
||||
completed: ['UNDER_REVIEW', 'SEMIFINALIST', 'FINALIST', 'WINNER'].includes(project.status),
|
||||
date: currentStatus === 'SUBMITTED' && project.submittedAt ? project.submittedAt : null,
|
||||
completed: ['UNDER_REVIEW', 'SEMIFINALIST', 'FINALIST', 'WINNER'].includes(currentStatus),
|
||||
},
|
||||
{
|
||||
status: 'SEMIFINALIST',
|
||||
label: 'Semi-finalist',
|
||||
date: null, // Would need status change tracking
|
||||
completed: ['SEMIFINALIST', 'FINALIST', 'WINNER'].includes(project.status),
|
||||
completed: ['SEMIFINALIST', 'FINALIST', 'WINNER'].includes(currentStatus),
|
||||
},
|
||||
{
|
||||
status: 'FINALIST',
|
||||
label: 'Finalist',
|
||||
date: null,
|
||||
completed: ['FINALIST', 'WINNER'].includes(project.status),
|
||||
completed: ['FINALIST', 'WINNER'].includes(currentStatus),
|
||||
},
|
||||
]
|
||||
|
||||
return {
|
||||
project,
|
||||
timeline,
|
||||
currentStatus: project.status,
|
||||
currentStatus,
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -474,10 +509,15 @@ export const applicantRouter = router({
|
||||
],
|
||||
},
|
||||
include: {
|
||||
round: {
|
||||
roundProjects: {
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
round: {
|
||||
include: {
|
||||
program: { select: { name: true, year: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { addedAt: 'desc' },
|
||||
},
|
||||
files: true,
|
||||
teamMembers: {
|
||||
|
||||
Reference in New Issue
Block a user