Dorian Niemiec
a4cadaac3a
All checks were successful
Deploy Next.js application / deploy (push) Successful in 8m5s
33 lines
964 B
TypeScript
33 lines
964 B
TypeScript
// app/api/delete/[id]/route.ts
|
|
import clientPromise from "@/lib/db";
|
|
import { ObjectId } from "mongodb";
|
|
import { NextResponse } from "next/server";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
export async function DELETE(
|
|
request: Request,
|
|
props: { params: Promise<{ id: string }> }
|
|
) {
|
|
const params = await props.params;
|
|
const { id } = params;
|
|
|
|
try {
|
|
const client = await clientPromise;
|
|
const db = client.db(process.env.MONGODB_DB);
|
|
const collection = db.collection("logs");
|
|
|
|
const result = await collection.deleteOne({ _id: new ObjectId(id) });
|
|
|
|
if (result.deletedCount === 1) {
|
|
revalidatePath("/changelog");
|
|
return NextResponse.json({ message: "Log deleted successfully" });
|
|
} else {
|
|
return NextResponse.json({ message: "Log not found" }, { status: 404 });
|
|
}
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ message: "Failed to delete log", error: error },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|