Fix: DNF books not appearing in library filter#418
Merged
Conversation
Fixed critical bug where books with DNF status were not showing up when filtering by status on the library page. Root Cause: The book repository was treating DNF status like active statuses (reading, to-read, read-next) by requiring is_active = 1. However, DNF is a terminal state like 'read', where sessions are archived with is_active = 0. Changes: - Updated findWithFilters() to treat 'dnf' status like 'read' status - Updated findWithFiltersAndRelations() to treat 'dnf' status like 'read' - Added comprehensive test coverage for status filtering including DNF Impact: - Users can now filter for DNF books on the library page - All 3 DNF books in database now appear in filter results - Terminal states (read, dnf) properly include all sessions - Active states (reading, to-read, read-next) still require active sessions Tests: - Created book-status-filtering.test.ts with 9 new tests - All 4022 existing tests pass - Verified fix via API: /api/books?status=dnf returns 3 books Locations: - lib/repositories/book.repository.ts lines 377-380 - lib/repositories/book.repository.ts lines 754-757
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## develop #418 +/- ##
===========================================
+ Coverage 78.67% 78.70% +0.02%
===========================================
Files 167 167
Lines 7559 7559
Branches 1850 1850
===========================================
+ Hits 5947 5949 +2
Misses 1127 1127
+ Partials 485 483 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Owner
Author
|
@copilot review this PR |
Contributor
Reviewed. I ran targeted validation for this fix and automated PR/security review; the DNF status filter tests pass (9/9) and no additional code changes are required for this PR. Current commit: |
This was referenced Apr 16, 2026
Open
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.
Summary
Fixes critical bug where books with DNF (Did Not Finish) status were not showing up when filtering by status on the library page.
Root Cause
The book repository was incorrectly treating DNF status like active statuses (reading, to-read, read-next) by requiring
is_active = 1. However, DNF is a terminal/completed state like "read", where sessions are archived withis_active = 0.Before: DNF filter returned 0 books despite 3 DNF books existing in the database
After: DNF filter correctly returns all 3 DNF books
Changes
Repository Logic (
lib/repositories/book.repository.ts)findWithFilters()to treat 'dnf' status like 'read' status (lines 377-380)findWithFiltersAndRelations()to treat 'dnf' status like 'read' status (lines 754-757)is_activeis_active = 1Test Coverage (
__tests__/integration/repositories/books/book-status-filtering.test.ts)Added 9 comprehensive tests covering:
findWithFilters()andfindWithFiltersAndRelations()methodsTesting
/api/books?status=dnfreturns 3 books ✅is_active = 0✅Impact
Database Evidence
Related Files
lib/repositories/book.repository.ts(2 locations updated)__tests__/integration/repositories/books/book-status-filtering.test.ts(new file)