38 lines
906 B
TypeScript
38 lines
906 B
TypeScript
import clientPromise from "@/lib/db";
|
|
import { ObjectId } from "mongodb";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function DELETE(
|
|
request: Request,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
const { id } = params;
|
|
|
|
if (!id) {
|
|
return NextResponse.json({ message: "ID is required" }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const client = await clientPromise;
|
|
const db = client.db("downloadsDatabase");
|
|
const result = await db
|
|
.collection("vulnerabilities")
|
|
.deleteOne({ _id: new ObjectId(id) });
|
|
if (result.deletedCount === 1) {
|
|
return NextResponse.json(
|
|
{ message: "Vulnerability deleted successfully" },
|
|
{ status: 200 }
|
|
);
|
|
} else {
|
|
return NextResponse.json(
|
|
{ message: "Vulnerability not found" },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ message: "Failed to delete vulnerability" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|