aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/server/repositories/card.ts
diff options
context:
space:
mode:
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,