Files
football-next/app/api/quiz/my-results/route.ts
2026-05-13 15:46:27 +03:30

23 lines
640 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
import { getApiUser } from "@/lib/apiAuth";
// GET /api/quiz/my-results
export async function GET(req: NextRequest) {
const apiUser = await getApiUser(req);
if (!apiUser) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const userId = apiUser.id;
const submissions = await db.quizSubmission.findMany({
where: { userId },
include: {
quiz: {
include: { questions: { orderBy: { order: "asc" } } },
},
},
orderBy: { submittedAt: "desc" },
});
return NextResponse.json(submissions);
}