Skip to content

fix(applications): record when an application is submitted - #905

Merged
thinkclay merged 2 commits into
mainfrom
fix/application-submitted-at
Sep 25, 2026
Merged

thinkclay merged 2 commits into
mainfrom
fix/application-submitted-at

Conversation

@blink-dev

Copy link
Copy Markdown
Collaborator

Closes #881

A saved draft and a submitted application were the same row. is_complete only decided whether scoring ran; nothing stored it. So job detail said "You've applied" to anyone who had typed one answer, the worker's list showed abandoned forms as sent, and employers saw drafts on their board.

Separately, the wizard's Submit button PATCHed the auto-saved draft without is_complete, so most real submissions were never scored either.

Changes

Database

  • 359_application_submitted_at.sql adds core.applications.submitted_at. NULL means draft.
  • Backfill: every existing row counts as submitted. No existing row carries a reliable signal: most real submissions were never scored because of the Submit bug, so a rule based on score_calculated_at would pull real candidates off employer boards. Drafts abandoned before this change stay listed as applications; everything from now on is separated. The rule is written in the migration.

API

  • POST / PATCH /v1/applications set submitted_at the first time a request carries is_complete: true. Auto-saves never set it, and a repeat submit keeps the original time. The tRPC submit sets it too.
  • Submitting a draft through PATCH now runs the same job-open and deadline checks as create (jobClosedReason).
  • submitted_at is added to the Application response schema; /v1/jobs/:jobId/applications/me already returns it.
  • Employer board list and status updates exclude drafts; opening a draft by id returns 404. The list sorts and date-filters by submitted_at.
  • The EEO report counts submitted applications only, with its period applied to submitted_at.

Client

  • Submit now sends is_complete: true on the PATCH path and refreshes the cached application after submit.
  • The review step says "Submit Application" for a draft. It said "Update Application" for every draft, because edit mode was keyed on whether the draft existed.
  • Job detail: "You've applied" with "View status" once submitted; "Finish your application" with "Continue application" for a draft. The header button follows the same split.
  • Worker's Applications list: drafts sit in a "Not sent" group that links back to the form. The job list only marks a job as applied once submitted.

SDK (submodule, Scaffald/sdk#)

  • submitted_at added to Application and EmployerApplication.

Testing

  • Unit tests for the update payload (submit, auto-save, repeat submit), jobClosedReason and isDraft.
  • Checked through the API against the local database: draft → auto-save → submit → repeat submit; submit after the deadline returns 400.
  • Checked in the browser: draft shows as "Finish your application" and "Not sent"; submit shows "You've applied" and "Applied"; the Office board shows the submitted application and hides a draft.
  • applications.test.ts couldn't cover this: its test-user helper breaks before any request is sent.

@blink-dev
blink-dev force-pushed the fix/application-submitted-at branch from 381e179 to fbb22f9 Compare September 25, 2026 15:10
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@blink-dev

Copy link
Copy Markdown
Collaborator Author

This needs Scaffald/sdk#33 to be merged first so CI can succeed

Scaffald/sdk#33 is merged. `Application` and `EmployerApplication` now
carry `submitted_at`, which is what the four typecheck errors on this
branch were waiting for.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay

Copy link
Copy Markdown
Contributor

Unblocked the typecheck. Scaffald/sdk#33 is merged (348bf1d) and I pushed the pointer bump as ae72c07 — that is what the four Property 'submitted_at' does not exist on type 'Application' errors were waiting on. Worth noting for next time: the PR body's SDK line reads Scaffald/sdk# with no number, and the submodule pointer was never bumped, so the branch could not have gone green on its own.

Verified locally after the bump: scf-core and scaffald-app typecheck clean, and full pnpm prepush passes (195 migrations unique, search_path and service_role grants all clear).

On the substance, the part I looked at hardest is the backfill, because it is the one irreversible decision here:

UPDATE core.applications SET submitted_at = COALESCE(score_calculated_at, created_at)

Treating every existing row as submitted is the right call, and the migration explains why in the file rather than only in the PR — good. The reasoning holds: the Submit bug means score_calculated_at is absent on real submissions, so any narrower rule silently drops real candidates off employer boards, and a false positive here (a stale draft listed as an application) is recoverable by a human where a false negative is not. Worth stating plainly that this is one-way: after this runs, no row can be re-identified as a draft.

Two things I'd flag, neither blocking:

  1. No index on submitted_at. The employer board list now both sorts and date-filters on it (employer-applications.ts), and the EEO report applies its period to it. That is a sequential scan on a column with no index. Fine at today's row counts; worth a follow-up before it isn't.

  2. The PATCH job-open check is skipped on re-submit. if (input.is_complete && !existing.submitted_at) means jobClosedReason only runs on the first submit. A repeat submit against a closed job or a passed deadline goes through and re-triggers scoreAndScreen. That is probably intentional — you do not want to punish someone re-saving an application they already sent — but it is the kind of asymmetry worth a line of comment next to the guard so the next reader does not 'fix' it.

Merging once CI is green.

@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay thinkclay 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.

Green after the SDK pointer bump, including Run API Tests — which is the check that actually exercises the draft → auto-save → submit → repeat-submit path this PR is about.

Approving. The two notes in my earlier comment (no index on submitted_at; jobClosedReason skipped on re-submit) are follow-ups, not blockers.

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.

fix(applications): a saved draft and a submitted application are the same row

2 participants