/* ============================================================================= * M01_MasterData_UI_Matset_Api.ts * 자재 조합(`자재조합.json` · 키 UM) 서버 길 — 목록 · 하나 · 새로 · 고치기 · 지우기 * 계약: `resources/master_data/_화면_계약.md` 9장 「자재 조합」 * ========================================================================== */ import { API_BASE_URL } from "@config/config_frontend"; import { ApiError } from "./M01_MasterData_UI_Logic_Api"; /** 담은 자재 한 줄 — 고를 때의 사본(수량 · 단가는 안 둠) */ export interface MatItem { 코드: string; 이름: string; 규격: string; 단위: string; } export interface Matset { 키: string; 이름: string; 담은자재: MatItem[]; /** 본뜬 원본 자재 조합 키 — 비면 원본 */ 본뜬키: string | null; 소유: string | null; 비고: string | null; } export interface MatsetSummary extends Omit { count: number; } export interface MatsetOne { file: string; version: string; matset: Matset; } 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 fetchMatsets = (): Promise => request<{ matsets: MatsetSummary[] }>("/matsets").then((d) => d.matsets); export const fetchMatset = (key: string): Promise => request(`/matset?key=${encodeURIComponent(key)}`); export const newMatset = (matset: Matset): Promise<{ key: string; version: string }> => request("/matset/new", { matset }); export const editMatset = (key: string, version: string, matset: Matset): Promise => request("/matset/edit", { key, version, matset }); export const deleteMatset = (key: string, version: string): Promise => request("/matset/delete", { key, version });