Files
Momento/memento-note/app/api/mobile/flashcards/review/route.ts
Antigravity a84c7e80d6
All checks were successful
CI / Lint, Unit Tests & Build (push) Successful in 6m13s
CI / Deploy production (on server) (push) Successful in 24s
fix(critique): 2 régressions introduites par les fixes précédents
Bug #1 — Memory Echo cassé (runtime crash):
- lib/ai/services/memory-echo.service.ts: lignes adjustedThreshold restaurées
- Cause: sed console.log avait supprimé les lignes de définition
- Effet: findConnections() crashait (ReferenceError)

Bug #2 — Auth mobile totalement cassée (sécurité):
- 14 routes app/api/mobile/*/: getMobileUserId(req) → await getMobileUserId(req)
- Cause: verifyMobileToken devenu async mais callers non mis à jour
- Effet: auth bypassée (Promise truthy au lieu de string)

i18n:
- searchModal.* + insightsView.* propagés dans 13 locales (EN fallback)
2026-07-05 16:53:36 +00:00

41 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { getMobileUserId } from '@/lib/mobile-auth'
import { computeSm2Update } from '@/lib/flashcards/sm2'
export async function POST(req: NextRequest) {
const userId = await getMobileUserId(req)
if (!userId) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const body = await req.json()
const cardId = typeof body.cardId === 'string' ? body.cardId : null
const grade = typeof body.grade === 'number' ? body.grade : null
if (!cardId || grade === null || grade < 1 || grade > 4) {
return NextResponse.json({ error: 'cardId and grade (14) required' }, { status: 400 })
}
const card = await prisma.flashcard.findFirst({
where: { id: cardId, deck: { userId } },
select: { id: true, interval: true, easinessFactor: true },
})
if (!card) return NextResponse.json({ error: 'Card not found' }, { status: 404 })
const { easinessFactor, interval, nextReviewAt } = computeSm2Update(grade, {
easinessFactor: card.easinessFactor,
interval: card.interval,
})
await prisma.$transaction([
prisma.flashcard.update({
where: { id: cardId },
data: { easinessFactor, interval, nextReviewAt },
}),
prisma.flashcardReview.create({
data: { cardId, grade, reviewedAt: new Date() },
}),
])
return NextResponse.json({ ok: true, nextReviewAt, interval })
}