/* ============================================================================= * M01_MasterData_UI_Combo_Api.ts * 일위대가 조합 화면이 부르는 서버 길 — 조합 마스터 `일위대가조합.json`(키 UA) * 길 이름은 계약(PLAN 4-2)이 오면 이 파일만 맞춤 · 미리 보기는 로직마다 `/calc` 를 불러 화면에서 합침 * ========================================================================== */ import { API_BASE_URL } from "@config/config_frontend"; import { ApiError } from "./M01_MasterData_UI_Logic_Api"; /** 조합에 담은 로직 한 줄 — 입력 = 그 로직을 셀 때 넣을 값 */ export interface ComboLogic { 키: string; 메모: string; 입력: Record; } export interface Combo { 키: string; 이름: string; 구분: string; 상세구분: string; 단위: string; 비고: string; 로직: ComboLogic[]; } export interface ComboSummary { 키: string; 이름: string; 구분: string; 상세구분: string; 단위: string; 로직수: number; } async function request(path: string, body?: unknown): Promise { const response = await fetch(`${API_BASE_URL}/m01${path}`, { method: body === undefined ? "GET" : "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body), }); const data = (await response.json().catch(() => ({}))) as { detail?: unknown } & T; if (!response.ok) throw new ApiError(response.status, data.detail ?? response.statusText); return data; } export const fetchCombos = (): Promise => request<{ combos: ComboSummary[] }>("/combos").then((d) => d.combos); export const fetchCombo = (key: string): Promise => request<{ combo: Combo }>(`/combo?key=${encodeURIComponent(key)}`).then((d) => d.combo); /** 키가 비면 새 조합 — 서버가 다음 번호(UA…)를 줌 */ export const saveCombo = (combo: Combo): Promise => request<{ combo: Combo }>("/combo/save", { combo }).then((d) => d.combo); export const deleteCombo = (key: string): Promise => request("/combo/delete", { key });