Skip to content

feat(api): return post versions from GET /content/post/:slug - #214

Open
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:feature/192-post-versions
Open

feat(api): return post versions from GET /content/post/:slug#214
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:feature/192-post-versions

Conversation

@bbornino

@bbornino bbornino commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #192

What changed

GET /content/post/:slug now returns a versions array alongside the
existing collection field — the other versions of a post that share
its groupId.

  • Added a new self-referential versions relation on posts in
    packages/db/src/relations.ts, keyed on the (nullable) groupId
    column. A post with no groupId naturally resolves to zero relation
    matches, so no special-casing is needed for that case.
  • PostResponseSchema gained a versions: { slug, versionName, publishedAt }[] field.
  • The route handler fetches each version's slug, versionName,
    versionOrder, and publishedAt, then sorts by versionOrder
    first and publishedAt as a tiebreaker, per the issue.

Notes

  • The current post is intentionally excluded from its own versions
    list
    — the relation itself returns every post sharing the same
    groupId, including the post being requested, so the handler
    filters that entry out by slug before returning the array.
  • Unpublished versions are filtered out, the same way unpublished
    collection chapters are already excluded from collection.chapters
    in this route, to avoid leaking draft slugs through a public
    endpoint.
  • There's no createdAt column on posts (only editedAt and
    publishedAt), so publishedAt is reused as the version's date —
    same field name and value already exposed for the post itself and
    for collection chapters.

Test plan

  • pnpm test:unit passes clean
  • pnpm run build:all passes clean (full tsc type-check, not
    just vitest's esbuild transpile)
  • pnpm prettier --check clean on changed files
  • New test: a post with multiple versions, sorted by versionOrder
    then publishedAt, self excluded
  • New test: a post with no groupId returns an empty versions array

Adds a self-referential posts.versions relation keyed on groupId, and
exposes other versions of a post (slug, versionName, publishedAt) sorted
by versionOrder then publishedAt. Posts with no groupId, or versions that
aren't published, are simply omitted from the list rather than erroring.
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 639e1a8a-88ab-4a69-b0da-5423547f092a


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Return "post versions" from the post endpoint

1 participant