91 lines
2.6 KiB
TypeScript
91 lines
2.6 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { executeLegacyEconomyMutation } from "@/features/housekeeping/domains/economy/services/mutations";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import type { ActionResult } from "@/lib/safe-action-shared";
|
|
|
|
export async function updateCatalogPage({
|
|
id,
|
|
...fields
|
|
}: { id: number } & Record<string, unknown>): Promise<ActionResult> {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "catalog-page.change", {
|
|
action: "update",
|
|
id,
|
|
...fields,
|
|
});
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: {} };
|
|
}
|
|
|
|
export async function deleteCatalogPage({ id }: { id: number }) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "catalog-page.change", {
|
|
action: "delete",
|
|
id,
|
|
});
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: {} };
|
|
}
|
|
|
|
export async function toggleCatalogPage({
|
|
id,
|
|
action,
|
|
}: {
|
|
id: number;
|
|
action: "toggleEnabled" | "toggleVisible";
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "catalog-page.change", {
|
|
action: action === "toggleEnabled" ? "toggle-enabled" : "toggle-visible",
|
|
id,
|
|
});
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: {} };
|
|
}
|
|
|
|
export async function createCatalogPage(input: {
|
|
caption: string;
|
|
parentId: number;
|
|
pageLayout?: string;
|
|
iconImage?: number;
|
|
iconColor?: number;
|
|
enabled?: "0" | "1";
|
|
visible?: "0" | "1";
|
|
minRank?: number;
|
|
orderNum?: number;
|
|
}): Promise<ActionResult<{ id: number }>> {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
const snapshot = await executeLegacyEconomyMutation(
|
|
staff,
|
|
"catalog-page.change",
|
|
{ action: "create", ...input },
|
|
);
|
|
const createdId = Number(snapshot.output?.id);
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: { id: createdId } };
|
|
}
|
|
|
|
export async function reorderTreePage(input: {
|
|
pageId: number;
|
|
newParentId?: number;
|
|
newOrderNum: number;
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "catalog-page.reorder", input);
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: {} };
|
|
}
|
|
|
|
export async function deleteTreePage(input: {
|
|
pageId: number;
|
|
mode: "reparent" | "cascade";
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "catalog-page.delete-tree", input);
|
|
revalidatePath("/ase/economy/catalog");
|
|
return { ok: true as const, data: {} };
|
|
}
|