fix: assign project to round on creation (create ProjectRoundState)

- Add optional roundId field to project.create mutation input schema
- After project creation, update project.roundId FK and create a
  ProjectRoundState record (state: PENDING) when roundId is supplied
- Pass selectedRoundId from the new-project form to createProject.mutate()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 14:31:08 +01:00
parent 25e06e11e4
commit 36560a1837
2 changed files with 16 additions and 0 deletions

View File

@@ -216,6 +216,7 @@ function NewProjectPageContent() {
createProject.mutate({ createProject.mutate({
programId: selectedProgramId, programId: selectedProgramId,
roundId: selectedRoundId || undefined,
title: title.trim(), title: title.trim(),
teamName: teamName.trim() || undefined, teamName: teamName.trim() || undefined,
description: description.trim() || undefined, description: description.trim() || undefined,

View File

@@ -484,6 +484,7 @@ export const projectRouter = router({
.input( .input(
z.object({ z.object({
programId: z.string(), programId: z.string(),
roundId: z.string().optional(),
title: z.string().min(1).max(500), title: z.string().min(1).max(500),
teamName: z.string().optional(), teamName: z.string().optional(),
description: z.string().optional(), description: z.string().optional(),
@@ -553,6 +554,20 @@ export const projectRouter = router({
}, },
}) })
if (input.roundId) {
await tx.project.update({
where: { id: created.id },
data: { roundId: input.roundId },
})
await tx.projectRoundState.create({
data: {
projectId: created.id,
roundId: input.roundId,
state: 'PENDING',
},
})
}
// Create team members if provided // Create team members if provided
const inviteList: { userId: string; email: string; name: string }[] = [] const inviteList: { userId: string; email: string; name: string }[] = []
if (teamMembersInput && teamMembersInput.length > 0) { if (teamMembersInput && teamMembersInput.length > 0) {