Files
EpicNext-Cms/src/actions/admin-vouchers.ts
T
Simo 9c4b973faf
CI / check (pull_request) Successful in 40s
CI / release (pull_request) Skipped
CI / deploy (pull_request) Skipped
feat(housekeeping): deliver economy vertical
2026-08-30 13:47:06 +02:00

53 lines
1.4 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,
actionError,
actionOk,
} from "@/lib/safe-action-shared";
import { logServerError } from "@/lib/server-log";
export async function createVoucher(input: {
code: string;
amount: number;
maxUses: number;
expiresAt?: string;
}): Promise<ActionResult<{ id: string }>> {
const staff = await requirePermission(PERMS.SHOP_EDIT);
try {
const snapshot = await executeLegacyEconomyMutation(
staff,
"voucher.change",
{ action: "create", ...input },
);
revalidatePath("/admin/vouchers");
return actionOk({ id: String(snapshot.output?.id) });
} catch (error) {
logServerError("admin.voucher_create_failed", error);
return actionError("Could not create voucher (code may already exist)");
}
}
export async function deleteVoucher(input: {
id: string;
}): Promise<ActionResult> {
const staff = await requirePermission(PERMS.SHOP_EDIT);
try {
await executeLegacyEconomyMutation(staff, "voucher.change", {
action: "delete",
id: input.id,
});
revalidatePath("/admin/vouchers");
return actionOk();
} catch (error) {
logServerError("admin.voucher_delete_failed", error, {
voucherId: input.id,
});
return actionError("Could not delete voucher");
}
}