Files
Aislo/M01_MasterData/M01_MasterData_UI_Matset_Api.ts
T
eomsangdonandClaude Sonnet 5 4c8ee6828f feat(M01): 자재 조합 화면 — 목록 · 상세 · 자재 더하기 · 지우기 알림
- 좌측 「자재 조합」 컨테이너(찾기) + 우측 목록(키 · 이름 · 자재 수 · 본뜬키 · 소유) · 상세(이름 · 비고 · 본뜬키 · 담은 자재 표 · 빼기)
- [자재 더하기] = 자재DB 낱말 찾기 → 하나씩 고름(이미 담은 자재는 잠김) · 저장 · 지우기는 M01 길 /api/m01/matset…
- 쓰는 구조물 열이 있어 지울 수 없으면 서버가 준 구조물 이름들을 알림으로 보임
- 알약 키 「이름|단위」 주석 갱신

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RoyUwuTFiDJfvCfHpvKKzp
2026-09-28 19:14:10 +09:00

61 lines
2.2 KiB
TypeScript

/* =============================================================================
* 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<Matset, "담은자재"> {
count: number;
}
export interface MatsetOne {
file: string;
version: string;
matset: Matset;
}
async function request<T>(path: string, body?: unknown): Promise<T> {
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<MatsetSummary[]> =>
request<{ matsets: MatsetSummary[] }>("/matsets").then((d) => d.matsets);
export const fetchMatset = (key: string): Promise<MatsetOne> =>
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<unknown> =>
request("/matset/edit", { key, version, matset });
export const deleteMatset = (key: string, version: string): Promise<unknown> =>
request("/matset/delete", { key, version });