37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server"
|
|
import { prisma } from "@/lib/db"
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json()
|
|
const { childId, session, attempts } = body
|
|
|
|
if (!childId || !session) {
|
|
return NextResponse.json({ error: "Missing required fields" }, { status: 400 })
|
|
}
|
|
|
|
const sessionLog = await prisma.sessionLog.create({
|
|
data: {
|
|
childId,
|
|
startedAt: new Date(session.startedAt),
|
|
endedAt: session.endedAt ? new Date(session.endedAt) : undefined,
|
|
durationSec: session.durationSec,
|
|
skillsPracticed: session.skillsPracticed,
|
|
skillAttempts: {
|
|
create: (attempts || []).map((a: any) => ({
|
|
skillCode: a.skillCode,
|
|
promptLevel: a.promptLevel ?? 0,
|
|
correct: a.correct,
|
|
responseMs: a.responseMs,
|
|
})),
|
|
},
|
|
},
|
|
})
|
|
|
|
return NextResponse.json({ success: true, sessionId: sessionLog.id })
|
|
} catch (error) {
|
|
console.error("Sync error:", error)
|
|
return NextResponse.json({ error: "Internal error" }, { status: 500 })
|
|
}
|
|
}
|