- 왼쪽 패널 「일위대가 조합」 컨테이너(단가산출 로직 아래) · 구분/상세구분 거름 · 새 조합 · 지우기 · 저장 - 상세: 이름·구분·단위·비고 + 담은 로직 표(올리기/내리기/빼기) · 로직 줄을 누르면 단가산출 로직 상세로 감 - 로직 더하기 창: 구분 → 상세구분 → 찾기로 하나씩 고름 - 미리 보기: 담은 로직별 입력값으로 계산해 노무비·재료비·경비 합계(보기만) - 서버 길(조합 목록·저장·지우기)은 아직 없어 Combo_Api 한 곳에 가정 이름으로 둠 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WRFJmmhPi4exAzHgPZHMT
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
/* =============================================================================
|
|
* 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<string, string>;
|
|
}
|
|
export interface Combo {
|
|
키: string;
|
|
이름: string;
|
|
구분: string;
|
|
상세구분: string;
|
|
단위: string;
|
|
비고: string;
|
|
로직: ComboLogic[];
|
|
}
|
|
export interface ComboSummary {
|
|
키: string;
|
|
이름: string;
|
|
구분: string;
|
|
상세구분: string;
|
|
단위: string;
|
|
로직수: number;
|
|
}
|
|
|
|
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 fetchCombos = (): Promise<ComboSummary[]> =>
|
|
request<{ combos: ComboSummary[] }>("/combos").then((d) => d.combos);
|
|
|
|
export const fetchCombo = (key: string): Promise<Combo> =>
|
|
request<{ combo: Combo }>(`/combo?key=${encodeURIComponent(key)}`).then((d) => d.combo);
|
|
|
|
/** 키가 비면 새 조합 — 서버가 다음 번호(UA…)를 줌 */
|
|
export const saveCombo = (combo: Combo): Promise<Combo> =>
|
|
request<{ combo: Combo }>("/combo/save", { combo }).then((d) => d.combo);
|
|
|
|
export const deleteCombo = (key: string): Promise<unknown> => request("/combo/delete", { key });
|