Files
Momento/memento-note/app/api/flashcards/decks/[id]/route.ts
Antigravity 0784c94242
Some checks failed
CI / Lint, Test & Build (push) Failing after 57s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): vues structurées tableau/kanban, flashcards et MCP robuste
Ajoute la base organisable par carnet (schéma, champs partagés, valeurs par note)
avec activation guidée, tableau éditable, kanban et suppression de colonnes.
Corrige le multiselect en vue tableau et enrichit sidebar, grille et i18n FR/EN.
Inclut aussi les améliorations flashcards SM-2, l'audit consentement IA et la
robustesse du serveur MCP (config, validation, rate-limit, métriques).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 23:03:16 +00:00

71 lines
2.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/auth'
import prisma from '@/lib/prisma'
import { getDeckDetail } from '@/lib/flashcards/deck-queries'
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id } = await params
const deck = await getDeckDetail(session.user.id, id)
if (!deck) {
return NextResponse.json({ error: 'Deck not found' }, { status: 404 })
}
const now = new Date()
const dueCount = deck.cards.filter((c) => c.due).length
const masteredCount = deck.cards.filter((c) => c.mastered).length
return NextResponse.json({
deck,
stats: {
total: deck.cards.length,
due: dueCount,
mastered: masteredCount,
},
})
} catch (error) {
console.error('[flashcards/decks/[id] GET]', error)
return NextResponse.json({ error: 'Failed to load deck' }, { status: 500 })
}
}
/**
* DELETE /api/flashcards/decks/[id]
* Permanently deletes the deck and all its cards (cascade via Prisma).
*/
export async function DELETE(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
try {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { id } = await params
const deck = await prisma.flashcardDeck.findFirst({
where: { id, userId: session.user.id },
})
if (!deck) {
return NextResponse.json({ error: 'Deck not found' }, { status: 404 })
}
await prisma.flashcardDeck.delete({ where: { id } })
return NextResponse.json({ ok: true })
} catch (error) {
console.error('[flashcards/decks/[id] DELETE]', error)
return NextResponse.json({ error: 'Failed to delete deck' }, { status: 500 })
}
}