feat(api): return post versions from GET /content/post/:slug - #214
Open
bbornino wants to merge 1 commit into
Open
feat(api): return post versions from GET /content/post/:slug#214bbornino wants to merge 1 commit into
bbornino wants to merge 1 commit into
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #192
What changed
GET /content/post/:slugnow returns aversionsarray alongside theexisting
collectionfield — the other versions of a post that shareits
groupId.versionsrelation onpostsinpackages/db/src/relations.ts, keyed on the (nullable)groupIdcolumn. A post with no
groupIdnaturally resolves to zero relationmatches, so no special-casing is needed for that case.
PostResponseSchemagained aversions: { slug, versionName, publishedAt }[]field.slug,versionName,versionOrder, andpublishedAt, then sorts byversionOrderfirst and
publishedAtas a tiebreaker, per the issue.Notes
list — the relation itself returns every post sharing the same
groupId, including the post being requested, so the handlerfilters that entry out by slug before returning the array.
collection chapters are already excluded from
collection.chaptersin this route, to avoid leaking draft slugs through a public
endpoint.
createdAtcolumn onposts(onlyeditedAtandpublishedAt), sopublishedAtis 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:unitpasses cleanpnpm run build:allpasses clean (fulltsctype-check, notjust vitest's esbuild transpile)
pnpm prettier --checkclean on changed filesversionOrderthen
publishedAt, self excludedgroupIdreturns an emptyversionsarray