35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getServerSession } from "@/lib/auth";
|
|
import { db } from "@/lib/db";
|
|
import { campaigns } from "@/lib/db/schema";
|
|
import { eq } from "drizzle-orm";
|
|
|
|
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ campaignId: string }> }) {
|
|
const session = await getServerSession();
|
|
if (!session || !session.isAdmin) {
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
}
|
|
const { campaignId } = await params;
|
|
db.delete(campaigns).where(eq(campaigns.id, campaignId)).run();
|
|
return NextResponse.json({ ok: true });
|
|
}
|
|
|
|
export async function PATCH(req: NextRequest, { params }: { params: Promise<{ campaignId: string }> }) {
|
|
const session = await getServerSession();
|
|
if (!session || !session.isAdmin) {
|
|
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
|
}
|
|
try {
|
|
const { campaignId } = await params;
|
|
const body = await req.json();
|
|
const updates: Record<string, unknown> = {};
|
|
if (body.name) updates.name = body.name;
|
|
if (body.status) updates.status = body.status;
|
|
if (body.gridSize) updates.gridSize = body.gridSize;
|
|
db.update(campaigns).set(updates).where(eq(campaigns.id, campaignId)).run();
|
|
return NextResponse.json({ ok: true });
|
|
} catch {
|
|
return NextResponse.json({ error: "Update failed" }, { status: 500 });
|
|
}
|
|
}
|