50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { logStaffActivity } from "@/lib/services/staff-activity";
|
|
|
|
export async function deletePhoto(formData: FormData): Promise<void> {
|
|
const staff = await requirePermission(PERMS.PAGES_EDIT);
|
|
const id = Number(formData.get("id"));
|
|
if (!(id > 0)) return;
|
|
|
|
try {
|
|
await prisma.cameraWeb.delete({ where: { id } });
|
|
await logStaffActivity({
|
|
staffId: staff.id,
|
|
action: "photo_delete",
|
|
description: `Deleted camera photo #${id}`,
|
|
targetType: "camera_web",
|
|
targetId: id,
|
|
});
|
|
} catch {
|
|
// Record may have already been removed; ignore.
|
|
}
|
|
|
|
revalidatePath("/admin/photos");
|
|
}
|
|
|
|
export async function bulkDeletePhotos(formData: FormData): Promise<void> {
|
|
const staff = await requirePermission(PERMS.PAGES_EDIT);
|
|
const raw = String(formData.get("ids") ?? "");
|
|
const ids = raw
|
|
.split(",")
|
|
.map((s) => Number(s.trim()))
|
|
.filter((n) => Number.isFinite(n) && n > 0);
|
|
if (ids.length === 0) return;
|
|
|
|
const result = await prisma.cameraWeb.deleteMany({
|
|
where: { id: { in: ids } },
|
|
});
|
|
await logStaffActivity({
|
|
staffId: staff.id,
|
|
action: "photo_bulk_delete",
|
|
description: `Deleted ${result.count} camera photo(s)`,
|
|
targetType: "camera_web",
|
|
});
|
|
revalidatePath("/admin/photos");
|
|
}
|