import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi"; import type { ReferenceRow } from "@/app/lib/types"; // Client-side wrapper for the /reference management page (add-admin-reference-data). Calls // only the portal's own /api/reference/** route handlers (spec: "the portal calls via // app/api/reference/[table]/** forwarding the admin JWT") — never solvway-mobile-api directly. /** Create/edit payload: `code` is only writable on CREATE (immutable after). */ export type ReferenceRowPayload = Omit; export async function listReferenceRows(table: string): Promise { return apiGet(`/api/reference/${table}`); } /** Create: always POSTs without an id (the row gets its id upstream). */ export async function createReferenceRow( table: string, payload: ReferenceRowPayload, ): Promise { return apiPost(`/api/reference/${table}`, payload); } /** Update: PUTs to the row's own URL; the id is in the path, not the body. */ export async function updateReferenceRow( table: string, id: number, payload: ReferenceRowPayload, ): Promise { return apiPut(`/api/reference/${table}/${id}`, payload); }