"use server"; import { revalidatePath } from "next/cache"; import { currentUserId } from "@/lib/auth/session"; import { runMutation, type ActionResult } from "@/lib/db/rpc"; const POSITION_PATHS = ["/positions", "/orgchart", "/"]; async function callRpc( fn: "create_position" | "delete_position", payload: Record, revalidate: string[] ): Promise { const result = await runMutation(await currentUserId(), fn, payload); if (!result.success) return result; for (const path of revalidate) revalidatePath(path); return result; } export async function createPosition(payload: { org_unit_id: string; job_title: string; is_chief: boolean; valid_from: string; }): Promise { return callRpc("create_position", payload, POSITION_PATHS); } export async function deletePosition(positionId: string): Promise { return callRpc("delete_position", { position_id: positionId }, POSITION_PATHS); }