131 lines
3.2 KiB
TypeScript
131 lines
3.2 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";
|
|
|
|
function revalidateBuilderClub(): void {
|
|
revalidatePath("/ase/economy/catalog");
|
|
}
|
|
|
|
export async function updateBcPage({
|
|
id,
|
|
...fields
|
|
}: { id: number } & Record<string, unknown>) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-page.change", {
|
|
action: "update",
|
|
id,
|
|
...fields,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const };
|
|
}
|
|
|
|
export async function deleteBcItem({ id }: { id: number }) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-item.change", {
|
|
action: "delete",
|
|
id,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const };
|
|
}
|
|
|
|
export async function updateBcItem({
|
|
id,
|
|
...data
|
|
}: {
|
|
id: number;
|
|
itemIds?: string;
|
|
catalogName?: string;
|
|
orderNumber?: number;
|
|
extradata?: string;
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-item.change", {
|
|
action: "update",
|
|
id,
|
|
...data,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const };
|
|
}
|
|
|
|
export async function createBcItem({
|
|
pageId,
|
|
...data
|
|
}: {
|
|
pageId: number;
|
|
itemIds: string;
|
|
catalogName: string;
|
|
orderNumber: number;
|
|
extradata: string;
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
const snapshot = await executeLegacyEconomyMutation(staff, "bc-item.change", {
|
|
action: "create",
|
|
pageId,
|
|
...data,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const, data: { id: Number(snapshot.output?.id) } };
|
|
}
|
|
|
|
export async function toggleBcPage({
|
|
id,
|
|
field,
|
|
}: {
|
|
id: number;
|
|
field: "enabled" | "visible";
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-page.change", {
|
|
action: field === "enabled" ? "toggle-enabled" : "toggle-visible",
|
|
id,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const };
|
|
}
|
|
|
|
export async function createBcPage(input: {
|
|
caption: string;
|
|
parentId: number;
|
|
pageLayout?: string;
|
|
iconImage?: number;
|
|
iconColor?: number;
|
|
enabled?: "0" | "1";
|
|
visible?: "0" | "1";
|
|
orderNum?: number;
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
const snapshot = await executeLegacyEconomyMutation(staff, "bc-page.change", {
|
|
action: "create",
|
|
...input,
|
|
});
|
|
revalidateBuilderClub();
|
|
return { ok: true as const, data: { id: Number(snapshot.output?.id) } };
|
|
}
|
|
|
|
export async function reorderBcTreePage(input: {
|
|
pageId: number;
|
|
newParentId?: number;
|
|
newOrderNum: number;
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-page.reorder", input);
|
|
revalidateBuilderClub();
|
|
return { ok: true as const, data: {} };
|
|
}
|
|
|
|
export async function deleteBcTreePage(input: {
|
|
pageId: number;
|
|
mode: "reparent" | "cascade";
|
|
}) {
|
|
const staff = await requirePermission(PERMS.CATALOG_EDIT);
|
|
await executeLegacyEconomyMutation(staff, "bc-page.delete-tree", input);
|
|
revalidateBuilderClub();
|
|
return { ok: true as const, data: {} };
|
|
}
|