diff --git a/src/app/api/link/list/[id]/route.tsx b/src/app/api/link/list/[id]/route.tsx index 17c9dee8..57362d81 100644 --- a/src/app/api/link/list/[id]/route.tsx +++ b/src/app/api/link/list/[id]/route.tsx @@ -3,23 +3,27 @@ import { NextRequest } from "next/server"; import clientPromise from "../../../../../lib/mongodb"; -export async function GET(request: NextRequest) { +export async function GET( + request: NextRequest, + { params }: { params: { id: string } }, +) { try { - const { searchParams } = new URL(request.url); - const id = searchParams.get("id"); - if (id) { - const client = await clientPromise; - const db = client.db("linkle"); - const collection = db.collection("userdata"); - const userId = id; - - const userData = await collection.find({ userId: userId }).toArray(); - const data = userData.length > 0 ? userData[0].data : []; + const id = params.id; + if (!id) { return NextResponse.json( - { message: "Success to get blocks", data }, - { status: 200 }, + { message: "ID parameter is required" }, + { status: 400 }, ); } + const client = await clientPromise; + const db = client.db("linkle"); + const collection = db.collection("userdata"); + const userData = await collection.find({ userId: id }).toArray(); + const data = userData.length > 0 ? userData[0].data : []; + return NextResponse.json( + { message: "Success to get blocks", data }, + { status: 200 }, + ); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error";