Skip to content

fix(api): detail endpoint returns participants + latest_version (#853) - #856

Merged
neuromechanist merged 1 commit into
devfrom
fix/issue-853-detail-participants
Jun 28, 2026
Merged

neuromechanist merged 1 commit into
devfrom
fix/issue-853-detail-participants

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

What

GET /datasets/:id did SELECT d.*, which exposes the raw subject_count column but not the participants alias the list/search endpoints return, and no latest_version (a computed subquery, not a table column). This adds both to the detail projection alongside d.*.

COALESCE(d.subject_count, 0) AS participants,
(
  SELECT version FROM dataset_versions dv
  WHERE dv.dataset_id = d.dataset_id
  ORDER BY created_at DESC
  LIMIT 1
) AS latest_version,

Why

The website's Discover search results hydrate each hit through /datasets/:id to pick up description/size/citations, but the detail row's participants: null overwrote the good value from the search projection, so search-result cards rendered no subject count (HBN / face-processing datasets, etc.). The frontend shipped a backfillSearchHit stopgap; this is the root-cause fix on the contract side. Once this lands, that stopgap can be removed.

Contract safety (no regression)

  • Additive only. d.* is untouched, so every existing field (including the raw subject_count) is unchanged. Two new fields are added: participants, latest_version.
  • No participants or latest_version raw column exists on datasets (verified across migrations: subject_count added in 0020; latest_version lives only on the deprecated nemar_catalog table), so there is no d.* name collision.
  • Projection is copied verbatim from the list endpoints (datasets.ts ~713 and ~760/770) so detail and list agree.

Testing

  • bun run typecheck (root + backend) green.
  • bun test datasets route units: 68 pass / 0 fail (unchanged from dev).
  • D1 result-shape is verified post-deploy via the live api-test suite, per the repo's no-mock / no-fabricated-D1-data policy (cf. test/data-records-route.test.ts). Spot-check after deploy:
    curl -s https://api.nemar.org/datasets/on005516 | jq '.dataset | {participants, latest_version}'
    # expect: { "participants": 430, "latest_version": "1.0.0" }   (currently both null)
    

Closes #853.

GET /datasets/:id did SELECT d.*, exposing the raw subject_count
column but not the participants alias, and no latest_version (that
is a computed subquery, not a table column). The list + search
endpoints both return participants + latest_version, so search-card
hydration that rehydrates via the detail endpoint lost the subject
count. Add both alongside d.* (additive; raw columns untouched, so
no contract regression). Closes #853.
@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR856

Version: 0.8.71-PR856.f883dcd
Commit: f883dcd


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit e10bd88 into dev Jun 28, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the fix/issue-853-detail-participants branch June 28, 2026 21:16

This branch was previously deployed

1 inactive deployment
npm — f883dcdf Deployed Jun 28, 2026 by neuromechanist via publish #1605
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