aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/server/repositories/card.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-05 22:49:03 +0900
committernsfisis <nsfisis@gmail.com>2026-02-05 22:49:03 +0900
commit504ff72fea72eb3d7c4cf45be1bd9620cb12a796 (patch)
treeffc4761292a60c039e8388ac4b4a020bf1c8d401 /src/server/repositories/card.ts
parent792891c4bb1cce34a4d11bd7fd5388804bff4ca6 (diff)
downloadkioku-504ff72fea72eb3d7c4cf45be1bd9620cb12a796.tar.gz
kioku-504ff72fea72eb3d7c4cf45be1bd9620cb12a796.tar.zst
kioku-504ff72fea72eb3d7c4cf45be1bd9620cb12a796.zip
fix(decks): align due card count with study screen limits
The deck list was showing all due cards without applying the newCardsPerDay limit or review card limit (100), causing a mismatch with the actual number of cards available in the study screen. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/server/repositories/card.ts')
-rw-r--r--src/server/repositories/card.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/server/repositories/card.ts b/src/server/repositories/card.ts
index f546922..d382f4d 100644
--- a/src/server/repositories/card.ts
+++ b/src/server/repositories/card.ts
@@ -221,6 +221,38 @@ export const cardRepository: CardRepository = {
return result[0]?.count ?? 0;
},
+ async countDueNewCards(deckId: string, now: Date): Promise<number> {
+ const boundary = getEndOfStudyDayBoundary(now);
+ const result = await db
+ .select({ count: sql<number>`count(*)::int` })
+ .from(cards)
+ .where(
+ and(
+ eq(cards.deckId, deckId),
+ isNull(cards.deletedAt),
+ lt(cards.due, boundary),
+ eq(cards.state, CardState.New),
+ ),
+ );
+ return result[0]?.count ?? 0;
+ },
+
+ async countDueReviewCards(deckId: string, now: Date): Promise<number> {
+ const boundary = getEndOfStudyDayBoundary(now);
+ const result = await db
+ .select({ count: sql<number>`count(*)::int` })
+ .from(cards)
+ .where(
+ and(
+ eq(cards.deckId, deckId),
+ isNull(cards.deletedAt),
+ lt(cards.due, boundary),
+ ne(cards.state, CardState.New),
+ ),
+ );
+ return result[0]?.count ?? 0;
+ },
+
async findDueCardsWithNoteData(
deckId: string,
now: Date,