diff --git a/src/app/decks/[deck_id]/InDeck.tsx b/src/app/decks/[deck_id]/InDeck.tsx index d6a6330..772e730 100644 --- a/src/app/decks/[deck_id]/InDeck.tsx +++ b/src/app/decks/[deck_id]/InDeck.tsx @@ -18,6 +18,7 @@ import type { ActionOutputCardWithNote } from "@/modules/card/card-action-dto"; import type { ActionOutputTodayStudyStats } from "@/modules/card/card-action-dto"; import type { ActionOutputDeck } from "@/modules/deck/deck-action-dto"; import { toast } from "sonner"; +import { DEFAULT_NEW_PER_DAY, DEFAULT_REV_PER_DAY } from "@/shared/constant"; export function InDeck({ deckId, isReadOnly }: { deckId: number; isReadOnly: boolean; }) { @@ -29,7 +30,7 @@ export function InDeck({ deckId, isReadOnly }: { deckId: number; isReadOnly: boo const [deckInfo, setDeckInfo] = useState(null); const [todayStats, setTodayStats] = useState(null); const [openSettingsModal, setSettingsModal] = useState(false); - const [settingsForm, setSettingsForm] = useState({ newPerDay: 20, revPerDay: 200 }); + const [settingsForm, setSettingsForm] = useState({ newPerDay: DEFAULT_NEW_PER_DAY, revPerDay: DEFAULT_REV_PER_DAY }); const [savingSettings, setSavingSettings] = useState(false); const router = useRouter(); const t = useTranslations("deck_id"); diff --git a/src/modules/card/card-repository.ts b/src/modules/card/card-repository.ts index ce03706..3043fa1 100644 --- a/src/modules/card/card-repository.ts +++ b/src/modules/card/card-repository.ts @@ -346,7 +346,8 @@ export async function repoGetTodayStudyStats( startOfToday.setUTCHours(0, 0, 0, 0); const todayStart = startOfToday.getTime(); - const revlogs = await prisma.revlog.findMany({ + const stats = await prisma.revlog.groupBy({ + by: ["type"], where: { card: { deckId: input.deckId, @@ -355,30 +356,29 @@ export async function repoGetTodayStudyStats( gte: todayStart, }, }, - select: { - id: true, - cardId: true, + _count: { type: true, }, }); - const stats: RepoOutputTodayStudyStats = { - newStudied: 0, - reviewStudied: 0, - learningStudied: 0, - totalStudied: 0, - }; + let newStudied = 0; + let reviewStudied = 0; + let learningStudied = 0; - for (const revlog of revlogs) { - stats.totalStudied++; - if (revlog.type === 0) { - stats.newStudied++; - } else if (revlog.type === 1) { - stats.learningStudied++; - } else if (revlog.type === 2 || revlog.type === 3) { - stats.reviewStudied++; + for (const stat of stats) { + if (stat.type === 0) { + newStudied = stat._count.type; + } else if (stat.type === 1) { + learningStudied = stat._count.type; + } else if (stat.type === 2 || stat.type === 3) { + reviewStudied += stat._count.type; } } - return stats; + return { + newStudied, + reviewStudied, + learningStudied, + totalStudied: newStudied + reviewStudied + learningStudied, + }; } diff --git a/src/shared/constant.ts b/src/shared/constant.ts index 0915727..c66cf09 100644 --- a/src/shared/constant.ts +++ b/src/shared/constant.ts @@ -19,4 +19,18 @@ export const LENGTH_MIN_TRANSLATOR_TEXT = 1; export const LENGTH_MAX_USERNAME = 30; export const LENGTH_MIN_USERNAME = 3; export const LENGTH_MAX_PASSWORD = 100; -export const LENGTH_MIN_PASSWORD = 8; \ No newline at end of file +export const LENGTH_MIN_PASSWORD = 8; + +export const FIELD_SEPARATOR = "\x1f"; + +export const DEFAULT_NEW_PER_DAY = 20; +export const DEFAULT_REV_PER_DAY = 200; + +export const SECONDS_PER_MINUTE = 60; +export const SECONDS_PER_HOUR = 3600; +export const SECONDS_PER_DAY = 86400; + +export const MS_PER_SECOND = 1000; +export const MS_PER_MINUTE = 60000; +export const MS_PER_HOUR = 3600000; +export const MS_PER_DAY = 86400000; \ No newline at end of file