2024-07-17 19:02:48 +02:00
|
|
|
// app/api/delete/[id]/route.ts
|
|
|
|
import clientPromise from "@/lib/db";
|
|
|
|
import { ObjectId } from "mongodb";
|
|
|
|
import { NextResponse } from "next/server";
|
2024-09-07 20:56:08 +02:00
|
|
|
import { revalidatePath } from "next/cache";
|
2024-07-17 19:02:48 +02:00
|
|
|
|
|
|
|
export async function DELETE(
|
2024-09-07 09:12:48 +02:00
|
|
|
request: Request,
|
2024-11-01 09:56:38 +01:00
|
|
|
props: { params: Promise<{ id: string }> }
|
2024-07-17 19:02:48 +02:00
|
|
|
) {
|
2024-11-01 09:56:38 +01:00
|
|
|
const params = await props.params;
|
2024-09-07 09:12:48 +02:00
|
|
|
const { id } = params;
|
2024-07-17 19:02:48 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
try {
|
|
|
|
const client = await clientPromise;
|
2024-09-07 21:11:11 +02:00
|
|
|
const db = client.db(process.env.MONGODB_DB);
|
2024-09-07 09:12:48 +02:00
|
|
|
const collection = db.collection("mods");
|
2024-07-17 19:02:48 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
const result = await collection.deleteOne({ _id: new ObjectId(id) });
|
2024-07-17 19:02:48 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
if (result.deletedCount === 1) {
|
2024-09-07 20:56:08 +02:00
|
|
|
revalidatePath("/mods");
|
2024-09-07 09:12:48 +02:00
|
|
|
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 }
|
|
|
|
);
|
|
|
|
}
|
2024-07-17 19:02:48 +02:00
|
|
|
}
|