import { NextRequest, NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; interface Params { params: Promise<{ id: string }>; } // GET links for a node export async function GET(request: NextRequest, { params }: Params) { try { const { id } = await params; const links = await prisma.link.findMany({ where: { nodeId: id }, orderBy: { createdAt: "desc" }, }); return NextResponse.json(links); } catch (error) { console.error("Failed to fetch links:", error); return NextResponse.json( { error: "Failed to fetch links" }, { status: 500 } ); } } // POST add a link to a node export async function POST(request: NextRequest, { params }: Params) { try { const { id: nodeId } = await params; const body = await request.json(); const { url, label } = body; if (!url) { return NextResponse.json( { error: "URL is required" }, { status: 400 } ); } const link = await prisma.link.create({ data: { nodeId, url, label: label || null, }, }); return NextResponse.json(link, { status: 201 }); } catch (error) { console.error("Failed to create link:", error); return NextResponse.json( { error: "Failed to create link" }, { status: 500 } ); } }