26 lines
1002 B
TypeScript
26 lines
1002 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "@/lib/auth-options";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { clearCourseProgress } from "@/lib/certificates";
|
|
|
|
export async function POST(req: Request) {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: "Nicht angemeldet." }, { status: 401 });
|
|
}
|
|
|
|
const body = (await req.json().catch(() => null)) as { courseId?: string } | null;
|
|
const courseId = body?.courseId?.trim();
|
|
if (!courseId) return NextResponse.json({ error: "courseId fehlt." }, { status: 400 });
|
|
|
|
const enrollment = await prisma.enrollment.findUnique({
|
|
where: { userId_courseId: { userId: session.user.id, courseId } },
|
|
});
|
|
if (!enrollment) return NextResponse.json({ error: "Nicht eingeschrieben." }, { status: 403 });
|
|
|
|
await clearCourseProgress(session.user.id, courseId);
|
|
|
|
return NextResponse.json({ ok: true });
|
|
}
|