Initial working commit
Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s

This commit is contained in:
Elijah 2026-06-27 19:19:38 -07:00
parent 666ceb7325
commit b7ce314f01
105 changed files with 35510 additions and 11 deletions

View file

@ -0,0 +1,79 @@
import { prisma } from "@/lib/db";
import type { FlashcardImportData } from "@/lib/validation/importSchemas";
export async function listDecksByClass(classId: string) {
return prisma.deck.findMany({
where: { classId },
orderBy: { sortOrder: "asc" },
include: {
_count: { select: { cards: true } },
progress: {
select: {
mode: true,
currentIndex: true,
orderJson: true,
cardResultsJson: true,
},
},
},
});
}
export async function getDeckWithCards(deckId: string) {
return prisma.deck.findUnique({
where: { id: deckId },
include: {
cards: { orderBy: { sortOrder: "asc" } },
class: { select: { slug: true, name: true } },
progress: true,
},
});
}
export async function createDeckFromImport(
classId: string,
data: FlashcardImportData,
overrideName?: string
) {
const maxOrder = await prisma.deck.aggregate({
where: { classId },
_max: { sortOrder: true },
});
const sortOrder = (maxOrder._max.sortOrder ?? -1) + 1;
return prisma.deck.create({
data: {
classId,
name: overrideName || data.deckName,
description: data.description,
sortOrder,
cards: {
create: data.cards.map((card, index) => ({
front: card.front,
back: card.back,
sortOrder: index,
})),
},
},
include: {
cards: true,
_count: { select: { cards: true } },
},
});
}
export async function updateDeck(
id: string,
data: { name?: string; description?: string }
) {
return prisma.deck.update({
where: { id },
data,
});
}
export async function deleteDeck(id: string) {
return prisma.deck.delete({
where: { id },
});
}