refactor: extract per-entity response serializers from route handlers (#23)
* refactor: extract per-entity response serializers from route handlers
Route handlers in topics.ts, categories.ts, and forum.ts manually mapped
DB rows to JSON with repeated serializeBigInt/serializeDate/serializeAuthor
calls. Extract reusable serializer functions to reduce duplication:
- serializePost(post, author) for topic posts and replies
- serializeCategory(cat) for category listings
- serializeForum(forum) for forum metadata
- Add CategoryRow and ForumRow type aliases
Update all route handlers to use the new serializers and add comprehensive
unit tests covering happy paths, null handling, and BigInt serialization.
* fix: remove log spam from serializeBigInt for null values
Null values are expected for optional BigInt fields like parentPostId
(null for topic posts) and forumId (null for orphaned categories).
Logging these creates noise without adding debugging value since the
null return is the correct behavior.
* test commit
* fix: remove broken turbo filter from lefthook pre-commit
The --filter='...[HEAD]' syntax doesn't work during merges and returns
zero packages in scope, causing turbo commands to fail with non-zero
exit codes even when checks pass.
Removing the filter makes turbo run on all packages with staged changes,
which is more reliable for pre-commit hooks.
* test: add integration tests for serialized GET endpoint responses
Addresses PR #23 'Important' feedback - adds comprehensive integration
tests that verify GET /api/forum and GET /api/categories return properly
serialized responses.
Tests verify:
- BigInt id fields serialized to strings
- Date fields serialized to ISO 8601 strings
- Internal fields (rkey, cid) not leaked
- Null optional fields handled gracefully
- Response structure matches serializer output
Also fixes:
- createTestContext() return type (TestContext not AppContext)
- Cleanup order (delete categories before forums for FK constraints)
All 249 tests pass.
* docs: add API response shape documentation to serializers
Addresses PR #23 'Suggestion' feedback - adds comprehensive JSDoc
comments documenting the JSON response shape for each serializer.
Documents:
- Field types and serialization (BigInt → string, Date → ISO 8601)
- Null handling for optional fields
- Response structure for GET /api/forum, /api/categories, /api/topics/:id
---------
Co-authored-by: Claude <noreply@anthropic.com>