Local Build and Deploy / deploy (push) Successful in 56s
Replace leftover requireStaff gates with module PERMS, drop hardcoded room rank thresholds, and expand contract tests so admin mutations cannot regress to dashboard-only checks. Co-authored-by: Cursor <[email protected]>
113 lines
3.0 KiB
TypeScript
113 lines
3.0 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { formPositiveBigInt } from "@/lib/form-data";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export async function createCategory(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SHOP_EDIT);
|
|
const name = String(formData.get("name") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
const badge = String(formData.get("badge") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
const priorityRaw = Number(formData.get("priority"));
|
|
const priority =
|
|
Number.isFinite(priorityRaw) && priorityRaw > 0
|
|
? Math.floor(priorityRaw)
|
|
: 1;
|
|
if (!name || !badge) return;
|
|
|
|
try {
|
|
await prisma.websiteRareValueCategories.create({
|
|
data: { name, badge, priority },
|
|
});
|
|
} catch {
|
|
// Unique name collision or DB error — ignore, page will re-render unchanged.
|
|
}
|
|
revalidatePath("/admin/rare-values");
|
|
}
|
|
|
|
export async function deleteCategory(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SHOP_EDIT);
|
|
const id = formPositiveBigInt(formData, "id");
|
|
if (!id) return;
|
|
|
|
try {
|
|
// Remove the category's values first to avoid orphaned rows.
|
|
await prisma.websiteRareValues.deleteMany({ where: { categoryId: id } });
|
|
await prisma.websiteRareValueCategories.delete({ where: { id } });
|
|
} catch {
|
|
// Not found or DB error — ignore.
|
|
}
|
|
revalidatePath("/admin/rare-values");
|
|
}
|
|
|
|
export async function createValue(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SHOP_EDIT);
|
|
const categoryId = formPositiveBigInt(formData, "categoryId");
|
|
if (!categoryId) return;
|
|
|
|
const name = String(formData.get("name") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
const furnitureIcon = String(formData.get("furnitureIcon") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
if (!name || !furnitureIcon) return;
|
|
|
|
const itemIdRaw = Number(formData.get("itemId"));
|
|
const itemId =
|
|
Number.isFinite(itemIdRaw) && itemIdRaw > 0 ? Math.floor(itemIdRaw) : null;
|
|
|
|
const creditValueRaw = String(formData.get("creditValue") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
const currencyValueRaw = String(formData.get("currencyValue") ?? "")
|
|
.normalize("NFC")
|
|
.trim()
|
|
.slice(0, 255);
|
|
const currencyType =
|
|
String(formData.get("currencyType") ?? "diamonds")
|
|
.trim()
|
|
.slice(0, 255) || "diamonds";
|
|
|
|
try {
|
|
await prisma.websiteRareValues.create({
|
|
data: {
|
|
categoryId,
|
|
itemId,
|
|
name,
|
|
creditValue: creditValueRaw || null,
|
|
currencyValue: currencyValueRaw || null,
|
|
currencyType,
|
|
furnitureIcon,
|
|
},
|
|
});
|
|
} catch {
|
|
// DB error — ignore.
|
|
}
|
|
revalidatePath("/admin/rare-values");
|
|
}
|
|
|
|
export async function deleteValue(formData: FormData): Promise<void> {
|
|
await requirePermission(PERMS.SHOP_EDIT);
|
|
const id = formPositiveBigInt(formData, "id");
|
|
if (!id) return;
|
|
|
|
try {
|
|
await prisma.websiteRareValues.delete({ where: { id } });
|
|
} catch {
|
|
// Not found or DB error — ignore.
|
|
}
|
|
revalidatePath("/admin/rare-values");
|
|
}
|