Files
edueasy/app/api/debug/state/route.ts
T
renato97 07929b6c60 feat: fase 4 — overhaul, docker, seguridad, métodos europeos
- Eliminada ruta duplicada /sebastian/sumas (código muerto)
- Removido topic 'sumas' del engine (reemplazado por 'matematicas')
- Creado docker-compose.yml (PostgreSQL + app, 1 comando install)
- Dockerfile: copiado prisma CLI al runner stage para db push
- APIs debug protegidas: 403 en producción (reset, state, seed)
- Audit métodos europeos: 24 archivos corregidos al 100%
  - Montessori: matemática Francesca + Sebastián
  - Decroly: lectura, ortografía, historia, geografía, banderas
  - Borel-Maisonny: lectura inicial Isabella (ya existía)
  - Freinet: expresión escrita Sebastián (ya existía)
- Validación prerequisitos: 0 rotos en contenido nuevo (157 ejercicios)
- INSTALL.md: guía completa de instalación
- fase4.md: documentación del overhaul
- E2E: 2 tests corregidos, 61/61 pasan
- TypeScript: exit 0, Build: exit 0
2026-07-25 22:34:05 -03:00

74 lines
2.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { prisma } from "@/lib/db"
import { getStagesForProfile } from "@/lib/curriculum/engine"
export async function GET(request: NextRequest) {
if (process.env.NODE_ENV === "production") {
return NextResponse.json({ error: "Not available in production" }, { status: 403 })
}
try {
const childId = request.nextUrl.searchParams.get("childId")
const profile = request.nextUrl.searchParams.get("profile") || "ISABELLA"
const topic = request.nextUrl.searchParams.get("topic") || "lectura"
if (!childId) {
return NextResponse.json({ error: "childId required" }, { status: 400 })
}
const child = await prisma.child.findUnique({
where: { id: childId },
select: { id: true, name: true, profile: true },
})
const progress = await prisma.curriculumProgress.findMany({
where: { childId },
orderBy: [{ topic: "asc" }, { stage: "asc" }],
})
const skillAttempts = await prisma.skillAttempt.findMany({
where: { sessionLog: { childId } },
orderBy: { createdAt: "desc" },
take: 20,
})
const fsrsCards = await prisma.fsrsCard.findMany({
where: { childId },
orderBy: { dueAt: "asc" },
})
const sessionLogs = await prisma.sessionLog.findMany({
where: { childId },
orderBy: { startedAt: "desc" },
take: 5,
})
// Count mastered exercises for this topic
const mastered = new Set(
skillAttempts
.filter((a) => a.exerciseId && a.exerciseId.startsWith(`${topic[0]}${topic[1]}`) && a.correct)
.map((a) => a.exerciseId),
)
const stages = await getStagesForProfile(profile, topic)
const totalExercises = Object.values(stages).reduce((sum, s) => sum + s.exercises.length, 0)
return NextResponse.json({
child,
progress,
skillAttempts: skillAttempts.slice(0, 10),
fsrsCards: fsrsCards.slice(0, 10),
sessionLogs,
stats: {
totalExercisesInTopic: totalExercises,
masteredInTopic: mastered.size,
progressPercent: totalExercises > 0 ? Math.round((mastered.size / totalExercises) * 100) : 0,
currentStage: progress.find((p) => !p.completedAt)?.stage || null,
currentTopic: progress.find((p) => !p.completedAt)?.topic || null,
},
})
} catch (error) {
console.error("Debug state error:", error)
return NextResponse.json({ error: "Internal error" }, { status: 500 })
}
}