import { apiGet, apiPost, apiPut, apiDelete } from "@/app/lib/clientApi"; import type { ModuleNode } from "@/app/lib/types"; // Client-side wrapper for the /modules management page (add-admin-module-node- // crud). Calls only the portal's own /api/modules/** route handlers (spec: // "Client calls SHALL go through app/api/modules/** route handlers forwarding // the admin JWT") — never solvway-mobile-api directly. /** Mutable create/edit payload: name is only writable on CREATE (immutable after). */ export interface ModuleNodePayload { name: string; desc?: string; type: "R" | "M" | "A"; url?: string; iconName?: string; parentId: number | null; } export async function listModules(): Promise { return apiGet("/api/modules"); } export async function createModule(payload: ModuleNodePayload): Promise { return apiPost("/api/modules", payload); } export async function updateModule(id: number, payload: ModuleNodePayload): Promise { return apiPut(`/api/modules/${id}`, payload); } export async function deleteModule(id: number): Promise { await apiDelete(`/api/modules/${id}`); }