Skip to content

fix: prevent submission duplicate creation and return full response on update#177

Merged
xGladiate merged 1 commit into
stagingfrom
fix/submission-duplicate-and-stale-response
May 19, 2026
Merged

fix: prevent submission duplicate creation and return full response on update#177
xGladiate merged 1 commit into
stagingfrom
fix/submission-duplicate-and-stale-response

Conversation

@jaejayrome

@jaejayrome jaejayrome commented May 19, 2026

Copy link
Copy Markdown
Contributor

Description

Prevent 500 Internal Server Error when "Start" is clicked multiple times by checking for existing submissions before creating
Include answers in PUT /api/submissions/:id response so the frontend can properly update submission status without requiring re-login

Problem

Two related bugs were reported on the evaluation dashboard:

  1. Double-click on "Start" causes 500 error: Clicking "Start" fires a POST /api/submissions request. If clicked again before navigating away (or if the first request is slow), a second POST with the same deadlineId + fromUserId + toProjectId violates the database unique constraint, returning:
    Unique constraint failed on the fields: (deadlineId,fromUserId,toProjectId)
    This locks the user out of the evaluation page until they sign out and back in.
  2. Submission status stuck on "Continue" after submitting: The PUT /api/submissions/:id endpoint successfully updates isDraft to false in the database, but the response only returned the bare submission record without answers. The frontend couldn't reconcile its local state with the incomplete response, so the UI continued showing "Continue" instead of "Edit" until a full page reload (via sign-out/sign-in) fetched fresh data.

Fix

createOneSubmission: Added a findFirstSubmission check before createUniqueSubmission. If a matching submission already exists, return it instead of attempting a duplicate insert.
updateOneSubmissionBySubmissionId: Added include: { answers: true } to the final findUniqueSubmission call so the response contains the full submission state.

Test plan (after deploying)

  1. Click "Start" on a submission, verify it navigates to the evaluation page
  2. Click "Start" again on the same submission — should return the existing submission (no 500 error)
  3. Fill out and submit a review — status should immediately show "Edit" without needing to sign out/in
  4. Verify updatedAt timestamp is reflected in the UI after submission

@jaejayrome
jaejayrome requested a review from xGladiate May 19, 2026 02:22

@xGladiate xGladiate left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Tested the changes locally and it is working as expected.

@xGladiate
xGladiate merged commit 3fe5521 into staging May 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants