Files
novi-lessons/Les06-NextJS-QuickPoll-Part2/quickpoll-les6-starter/src/app/api/polls/[id]/route.ts
2026-03-17 17:24:10 +01:00

28 lines
631 B
TypeScript

import { NextResponse } from "next/server";
import { getPollById } from "@/lib/data";
import type { Poll } from "@/types";
interface RouteParams {
params: Promise<{ id: string }>;
}
// STAP 3: GET /api/polls/[id] — enkele poll ophalen
// (Dit bestand is COMPLEET van Les 5. Dit is stap 3 van Les 5.)
export async function GET(
request: Request,
{ params }: RouteParams
): Promise<NextResponse> {
const { id } = await params;
const poll = getPollById(id);
if (!poll) {
return NextResponse.json(
{ error: "Poll niet gevonden" },
{ status: 404 }
);
}
return NextResponse.json<Poll>(poll);
}