Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/app/api/link/list/[id]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down