fix(dashboard): include read status in scroller cards

This commit is contained in:
neon
2026-05-14 23:54:14 -06:00
parent c4f9b289f6
commit 7d1435cbd3
2 changed files with 21 additions and 3 deletions
@@ -61,6 +61,8 @@ function makeFindCardsResult(idsInRowOrder: number[]) {
authorRows: [],
fileRows: idsInRowOrder.map((id) => ({ bookId: id, id: id * 10, format: 'epub', role: 'primary' })),
genreRows: [],
tagRows: [],
narratorRows: [],
progressRows: [],
statusRows: [],
total: idsInRowOrder.length,
@@ -109,13 +111,26 @@ describe('DashboardService', () => {
const user = makeUser({ id: 5 });
libraryService.findAccessibleLibraryIds.mockResolvedValue([100, 200]);
dashboardRepo.findRecentlyAddedBookIds.mockResolvedValue([9, 3]);
bookReadService.findCardsByBookIds.mockResolvedValue(makeFindCardsResult([3, 9]));
bookReadService.findCardsByBookIds.mockResolvedValue({
...makeFindCardsResult([3, 9]),
statusRows: [
{
bookId: 9,
status: 'reading',
source: 'manual',
startedAt: null,
finishedAt: null,
updatedAt: new Date('2026-01-03T00:00:00.000Z'),
},
],
});
const result = await service.getScroller(ScrollerType.RECENTLY_ADDED, user, 0);
expect(dashboardRepo.findRecentlyAddedBookIds).toHaveBeenCalledWith([100, 200], 1);
expect(bookReadService.findCardsByBookIds).toHaveBeenCalledWith([9, 3], 5);
expect(result.map((card) => card.id)).toEqual([9, 3]);
expect(result[0]?.readStatus?.status).toBe('reading');
});
it('routes continue reading requests to repository with clamped max limit', async () => {
@@ -22,8 +22,11 @@ export class DashboardService {
private async loadCardsByIds(bookIds: number[], userId: number): Promise<BookCard[]> {
if (bookIds.length === 0) return [];
const { rows, authorRows, fileRows, genreRows, progressRows } = await this.bookReadService.findCardsByBookIds(bookIds, userId);
const cards = assembleBookCards(rows, authorRows, fileRows, genreRows, progressRows);
const { rows, authorRows, fileRows, genreRows, progressRows, statusRows, narratorRows, tagRows } = await this.bookReadService.findCardsByBookIds(
bookIds,
userId,
);
const cards = assembleBookCards(rows, authorRows, fileRows, genreRows, progressRows, statusRows, narratorRows, tagRows);
const cardsById = new Map(cards.map((card) => [card.id, card]));
return bookIds.map((id) => cardsById.get(id)).filter((card): card is BookCard => card != null);
}