Files
edueasy/app/api/curriculum/progress/route.ts
T
renato97 a3360ec6e4 feat: fase 2+3 — expansion masiva multi-perfil + bug fixes + hardening
Fase 2 (expansion):
- Francesca: +6 etapas matematicas (5-10), +7 etapas lectura (3-9), +2 ortografia
- Sebastian: +8 etapas matematicas (4-11), +6 lectura, +3 historia, +3 geografia, +1 banderas
- Nuevas paginas: ortografia, lectura, geografia, matematicas
- ~900 ejercicios nuevos, paridad ~500 por perfil

Fase 3 (bug fixes + hardening):
- Fix: SessionLog auto-create en grade route
- Fix: engine cache (no borrar antes de revisar)
- Fix: FSRS cards actualizadas en flujo curriculum
- Fix: responseMs real (no hardcodeado 3000)
- Fix: options dentro de content en sebastian etapa-1
- Fix: trazo-letra consonantes crash
- Security: execFileSync anti-command-injection en TTS
- DB: 18 cascade deletes + indices + unique constraints
- APIs debug: reset, state, seed
- Docker: espeak-ng + prisma + user/group
- E2E: 23 tests nuevos (curriculum-flow.spec.ts)
- Code review: tailwind colors, middleware dev mode, eslint config

Verificado: tsc exit 0, build exit 0, 61 E2E tests pass
2026-07-25 22:07:28 -03:00

83 lines
2.5 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server"
import { prisma } from "@/lib/db"
import { initCurriculum, getLecturaStages, getNumerosStages } from "@/curriculum/index"
import { getCurrentStage, getNextExercise } from "@/lib/curriculum/engine"
export async function GET(request: NextRequest) {
try {
const childId = request.nextUrl.searchParams.get("childId")
const topic = (request.nextUrl.searchParams.get("topic") || "lectura") as "lectura" | "numeros"
if (!childId) {
return NextResponse.json({ error: "childId required" }, { status: 400 })
}
await initCurriculum()
const stages = topic === "lectura" ? getLecturaStages() : getNumerosStages()
const stageKeys = Object.keys(stages).map(Number).sort((a, b) => a - b)
const progress = prisma.curriculumProgress.findMany({
where: { childId, topic },
orderBy: { stage: "asc" },
})
const allAttempts = prisma.skillAttempt.findMany({
where: {
exerciseId: { not: null },
stage: { not: null },
sessionLog: { childId },
},
select: { exerciseId: true, correct: true },
})
const [progressRows, attempts] = await Promise.all([progress, allAttempts])
const mastered = new Set(
attempts.filter((a) => a.correct).map((a) => a.exerciseId),
)
const stagesInfo = stageKeys.map((sk) => {
const s = stages[sk]
const total = s?.exercises?.length || 0
const completed = s?.exercises?.filter((e) => mastered.has(e.id)).length || 0
const prog = progressRows.find((p) => p.stage === sk)
return {
stage: sk,
name: s?.name || `Etapa ${sk}`,
total,
completed,
unlocked: !!prog,
completedAt: prog?.completedAt || null,
percent: total > 0 ? Math.round((completed / total) * 100) : 0,
}
})
const errorTypes = await prisma.skillAttempt.groupBy({
by: ["errorType"],
where: {
errorType: { not: null },
sessionLog: { childId },
},
_count: { errorType: true },
})
const errorPatterns = errorTypes.map((e) => ({
errorType: e.errorType,
count: e._count.errorType,
}))
const activeProgress = progressRows.find((p) => !p.completedAt)
const currentStage = activeProgress?.stage || 1
return NextResponse.json({
currentStage,
stages: stagesInfo,
errorPatterns,
hasActiveSession: true,
})
} catch (error) {
console.error("Progress route error:", error)
return NextResponse.json({ error: "Internal error" }, { status: 500 })
}
}