Skip to content

fix(inquiries): make the application inquiry page actually load - #475

Merged
thinkclay merged 1 commit into
mainfrom
fix/443-inquiry-by-application
Jul 30, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/443-inquiry-by-application

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Fixes the reported symptom in #443. Part of #440.

Why it was broken

client.inquiries.getByApplication() did not exist. The call site hid that:

return (client.inquiries as unknown as InquiryCapabilityClient).getByApplication(applicationId)

The cast silenced the missing-method error, so it failed at runtime and the route fell into its error || !data branch and printed a red "Unable to load inquiry". Only the legacy tRPC router had a real implementation.

Server

New GET /v1/inquiries/by-application/{applicationId} (companion SDK method in Scaffald/sdk#11), ported from the tRPC procedure including its access rule — the applicant, the hiring organization's owner, or a user with a role assignment scoped to that organization.

Improvements over the port:

  • 404 and 403 are distinct. "No such application" and "not yours" are different answers and the UI needs to tell them apart. A query failure is 500, not silently treated as absence.
  • Returned bare, not under data. The SDK hands the body back verbatim and callers read .inquiry off it.
  • Also returns application/candidate/job/capabilityQuestions, because the office view reads data.candidate and data.job — omitting them would have quietly degraded that page to "Candidate" / "Job" placeholders.

Client

Cast removed, so the call is type-checked against the real SDK surface. That alone caught two inaccuracies the cast had been hiding, both corrected against the live schema:

  • InquiryComment was missing sender_id, content, read_by — all NOT NULL in core.inquiry_comments.
  • capabilityResponses denied null on response_value/response_text, which core.inquiry_capability_responses allows.

The empty state was the other half of the bug

Both inquiry routes treated "no inquiry exists" as a failure — the same red branch as a fetch error and as a bad application id. core.application_inquiries is empty in seed data, and most real applications never have an inquiry raised, so the ordinary case was being reported to users as broken. Now three distinct states, and the error branch surfaces the actual message instead of swallowing it.

Two schema bugs found by verifying rather than trusting

I ran every PostgREST select against the live local database instead of trusting the tRPC source:

  1. The legacy procedure selects columns that don't exist. applied_at and application_score are not on core.applications — that query 400s outright:
    {"code":"42703","message":"column applications.applied_at does not exist"}
    
    The real columns are created_at and score_total. Response keys are unchanged, so the views don't care.
  2. core.inquiries does not exist at all. The pre-existing GET/POST /v1/inquiries both read it, so both 500. That is a different concept from core.application_inquiries (this feature) — sender/recipient messaging vs. the ATS capability inquiry. Filed separately; not fixed here.

Verification

  • 12 new tests covering access decisions (applicant / owner / org member / stranger / missing / query error / array-shaped embeds) and the response mapping. Pass standalone and inside the full suite.
  • Every PostgREST select string executed against the live local DB.
  • scf-core and apps/scaffald typecheck clean with the cast gone. deno check on the route adds 0 errors to its 14 pre-existing ones (all from c.get() inferring as never, since authMiddleware uses an untyped Context — repo-wide, out of scope).
  • api suite: 119 passed / 59 failed before → 129–130 passed / 60–61 failed after. Two consecutive runs of identical code gave 129/61 and 130/60, so the existing suite is flaky at ±2; all 12 of mine pass in every run.

Not verified through the browser. The local edge runtime serves the primary working tree, which currently holds an unrelated in-progress changeset from a concurrent session, so I could not exercise the full HTTP path against my own build without disturbing it. The query strings are individually verified against the live database, but I have not seen the page render and am not claiming otherwise.

Still open on #443

The 15 other missing methods and their endpoints (createTemplate, applyTemplate, getSmartDefaults, createBulk, getMultiple, send, addComment, acceptSection, submitCapabilityResponse, update, changeStatus, …), plus the lint rule banning as unknown as on SDK clients. This PR fixes the reported page; the epic stays open.

The route rendered a red "Unable to load inquiry" because
`client.inquiries.getByApplication()` did not exist. An
`as unknown as InquiryCapabilityClient` cast in inquiries-sdk-hooks.ts silenced
the missing-method type error, so it failed at runtime instead. Only the legacy
tRPC router had a real implementation.

## Server

New GET /v1/inquiries/by-application/{applicationId}, ported from the tRPC
procedure, including its access rule: the applicant, the hiring organization's
owner, or a user with a role assignment scoped to that organization. 404 for
"no such application" and 403 for "not yours" are returned distinctly instead of
being collapsed, and a query failure is 500 rather than being mistaken for
absence. Returns the object bare, not under `data`, because the SDK hands the
body back verbatim and callers read `.inquiry` off it.

It also returns application/candidate/job/capabilityQuestions, because the
office view reads `data.candidate` and `data.job`; omitting them would have
silently degraded that page to "Candidate" / "Job" placeholders.

## Client

Cast removed, so this call is type-checked against the real SDK surface. That
alone caught two type inaccuracies the cast had been hiding, both corrected
against the live schema:

  * InquiryComment was missing sender_id, content, read_by (all NOT NULL)
  * capabilityResponses denied null on response_value / response_text, which
    core.inquiry_capability_responses allows

## Empty state

Both inquiry routes treated "no inquiry exists" as a failure — the same red
error branch as a fetch error and a bad application id. Since most applications
never have an inquiry raised, the ordinary case was reported to the user as
broken. They are now separate branches, and the error branch shows the actual
message instead of swallowing it.

## Two schema bugs found on the way

Validating each PostgREST select against the live database — rather than
trusting the tRPC source — turned up that the legacy procedure selects
`applied_at` and `application_score`, and neither column exists on
core.applications. That query would 400 outright. The real columns are
`created_at` and `score_total`; the response keys are unchanged so the views do
not care.

Separately, the pre-existing GET/POST /v1/inquiries read `core.inquiries`, a
table that does not exist in the database at all. Both endpoints 500. That is a
different concept from core.application_inquiries (this feature) and is filed
separately rather than fixed here.

## Verification

- 12 new tests covering the access decisions and the response mapping, passing
  standalone and inside the full suite
- Every PostgREST select string executed against the live local database
- scf-core and apps/scaffald typecheck clean with the cast gone; deno check on
  the route adds 0 errors to its 14 pre-existing ones
- api suite: 119 passed / 59 failed before, 129-130 passed / 60-61 failed after.
  Two consecutive runs of identical code gave 129/61 and 130/60, so the existing
  suite is flaky at about +/-2; all 12 of mine pass in every run

Not verified through the browser: the local edge runtime serves the primary
working tree, which currently holds an unrelated in-progress changeset from a
concurrent session, so I could not exercise the full HTTP path against my build.

Fixes the reported symptom in #443; the remaining 15 unported methods stay open
there. Refs #440

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 4424f61 into main Jul 30, 2026
5 of 13 checks passed
@thinkclay thinkclay mentioned this pull request Jul 30, 2026
@thinkclay
thinkclay deleted the fix/443-inquiry-by-application branch July 30, 2026 12:21
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.

1 participant