"use server"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { executeLegacyEconomyMutation } from "@/features/housekeeping/domains/economy/services/mutations"; import { requirePermission } from "@/lib/admin/guard"; import { PERMS } from "@/lib/permissions"; import { logServerError } from "@/lib/server-log"; function formInput(formData: FormData): Record { return Object.fromEntries(formData.entries()); } export async function createShopArticle(formData: FormData): Promise { const staff = await requirePermission(PERMS.SHOP_EDIT); try { await executeLegacyEconomyMutation(staff, "shop-article.change", { action: "create", ...formInput(formData), }); } catch (error) { logServerError("admin.shop_create_failed", error, { staffId: staff.id }); return; } redirect("/admin/shop"); } export async function updateShopArticle(formData: FormData): Promise { const staff = await requirePermission(PERMS.SHOP_EDIT); const input = formInput(formData); try { await executeLegacyEconomyMutation(staff, "shop-article.change", { action: "update", ...input, }); } catch (error) { logServerError("admin.shop_update_failed", error, { staffId: staff.id, articleId: String(input.id ?? ""), }); return; } revalidatePath(`/admin/shop/${String(input.id ?? "")}`); redirect("/admin/shop"); } export async function deleteShopArticle(formData: FormData): Promise { const staff = await requirePermission(PERMS.SHOP_EDIT); const input = formInput(formData); try { await executeLegacyEconomyMutation(staff, "shop-article.change", { action: "delete", ...input, }); } catch (error) { logServerError("admin.shop_delete_failed", error, { staffId: staff.id, articleId: String(input.id ?? ""), }); return; } redirect("/admin/shop"); }