Add endpoint to poll a creation's status

This commit is contained in:
Dan committed 2026-06-29 14:10:53 +00:00
1 parent e7759405ce
commit 9a7fd01eae
1 file changed
+17
+17
View File
@@ -0,0 +1,17 @@
import { NextResponse } from "next/server";
import { getCurrentUser } from "@/lib/session";
import { getCreatedById } from "@/lib/createdLessons";
// Poll the status of a creation (owner or admin).
export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) {
const user = await getCurrentUser();
if (!user) return NextResponse.json({ error: "Log in." }, { status: 401 });
const { id } = await ctx.params;
const row = getCreatedById(Number(id));
if (!row) return NextResponse.json({ error: "Not found." }, { status: 404 });
if (row.user_id !== user.id && user.role !== "admin")
return NextResponse.json({ error: "Not authorized." }, { status: 403 });
return NextResponse.json({ id: row.id, slug: row.slug, status: row.status, error: row.error, subject: row.subject });
}