Initial working commit
Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
Some checks failed
Automated Container Build / build-and-push (push) Failing after 7s
This commit is contained in:
parent
666ceb7325
commit
b7ce314f01
105 changed files with 35510 additions and 11 deletions
52
src/services/shareService.ts
Normal file
52
src/services/shareService.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { prisma } from "@/lib/db";
|
||||
|
||||
export async function getShareLink(token: string) {
|
||||
return prisma.shareLink.findUnique({
|
||||
where: { id: token },
|
||||
include: {
|
||||
deck: {
|
||||
include: {
|
||||
cards: { orderBy: { sortOrder: "asc" } },
|
||||
class: { select: { slug: true, name: true } },
|
||||
},
|
||||
},
|
||||
quizSet: {
|
||||
include: {
|
||||
questions: {
|
||||
orderBy: { sortOrder: "asc" },
|
||||
include: {
|
||||
options: { orderBy: { sortOrder: "asc" } },
|
||||
},
|
||||
},
|
||||
class: { select: { slug: true, name: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function getShareLinkForContent(targetType: "DECK" | "QUIZ", contentId: string) {
|
||||
if (targetType === "DECK") {
|
||||
return prisma.shareLink.findUnique({ where: { deckId: contentId } });
|
||||
}
|
||||
return prisma.shareLink.findUnique({ where: { quizSetId: contentId } });
|
||||
}
|
||||
|
||||
export async function toggleShareLink(targetType: "DECK" | "QUIZ", contentId: string) {
|
||||
const existing = await getShareLinkForContent(targetType, contentId);
|
||||
|
||||
if (existing) {
|
||||
// Disable sharing
|
||||
await prisma.shareLink.delete({ where: { id: existing.id } });
|
||||
return null;
|
||||
}
|
||||
|
||||
// Enable sharing
|
||||
return prisma.shareLink.create({
|
||||
data: {
|
||||
targetType,
|
||||
deckId: targetType === "DECK" ? contentId : null,
|
||||
quizSetId: targetType === "QUIZ" ? contentId : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue