import { NextResponse } from "next/server";
import { getPublicJobById } from "@/lib/db/queries";

export const dynamic = "force-dynamic";

export async function GET(
  _req: Request,
  { params }: { params: { id: string } }
) {
  const jobid = Number(params.id);

  if (Number.isNaN(jobid)) {
    return NextResponse.json({ error: "invalid id" }, { status: 400 });
  }

  const job = await getPublicJobById(jobid);

  if (!job) {
    return NextResponse.json({ error: "not found" }, { status: 404 });
  }

  return NextResponse.json({ item: job });
}
