Files
Aislo/M01_MasterData/M01_MasterData_UI_Logic_Api.ts
T
eomsangdonandClaude Opus 5.5 9e38ef0446 refactor(855-E L3ⓐ): M01 [로직 복사/생성] = 원본 수식 문서 복제 — 옛 별칭 꼴 시트 화면 걷음
- [로직 복사/생성] 누름 = 기본정보 창(있는 askBasicInfo · 원본 값 채움) → /logic/copy 로 원본 문서를 새 자체 GX 문서로 복제 → 그 기초를 줄 쌓기로 엶
- 걷음: 화면 LogicLab_Copy.ts · Logic_Calc.ts(부르는 곳 = 서로뿐) · API fetchLogicFormula · saveLogicFormula · previewLogicFormula · 꼴 셋 · 글 키 · CSS m01copy (서버 길 /logic/formula · save · preview 는 앞 auto 커밋 cce57c298 에서 걷음 · openapi 뜻한 셋만 빠짐)
- 시험: test_modal_top_and_add_word 복사 시트 창 줄 뺌(걷은 파일 · CSS 의 글자 대조 줄)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 08:37:59 +09:00

244 lines
8.5 KiB
TypeScript

/* =============================================================================
* M01_MasterData_UI_Logic_Api.ts
* 로직 화면이 부르는 서버 길 — 계약 `resources/master_data/_화면_계약.md` · `/api/m01`
* ========================================================================== */
import { API_BASE_URL } from "@config/config_frontend";
/** 로직 한 줄 — 파일 그대로(한글 칸) · 틀 `_틀.md` 6장 */
export interface LogicInput {
이름: string;
단위?: string;
고르기?: (string | number)[];
범위?: [number, number];
}
export interface HoLine {
종류: string;
요소: string;
이름?: string;
규격?: string;
단위?: string;
수량: string;
비목?: string;
}
export interface NamedFormula {
이름: string;
식: string;
비목?: string;
출처?: string;
}
export interface LogicRow {
/** 서버가 주는 키 — 새 로직은 "" (저장 때 대장의 다음 번호) */
키: string;
원문번호: string;
이름: string;
결과단위: string;
출처: string;
/** 원문 절 머리 개정 연도(빌더가 채움 · 읽기만 · 794-2b) */
개정?: number[];
소유?: string;
입력: LogicInput[];
중간: NamedFormula[];
호표?: HoLine[];
결과?: { 식: string };
덧줄?: NamedFormula[];
끝수?: string | null;
비고?: string;
/** 설계자가 찾는 다른 이름 — 쉼표로 여럿 · 없으면 칸 없음(208-1) */
별칭?: string;
[extra: string]: unknown;
}
export interface LogicSummary {
file: string;
구분: string;
상세구분: string;
키: string;
원문번호: string;
이름: string;
결과단위: string;
출처: string;
/** 없으면 빈칸(208-1) */
별칭?: string;
blocked: boolean;
reasons: string[];
}
export interface ElementBrief {
ref: string;
file?: string;
이름?: string;
규격?: string;
단위?: unknown;
값?: unknown;
값칸?: Record<string, string> | null;
/** 로직 그룹만 — 별칭(208-1) */
별칭?: string;
/** 재료 후보 줄 — 값 열 다섯(지역·계약종별별 값) */
값들?: Record<string, unknown>;
/** 재료 후보 줄 — 지역 · 상하차 칸(830-10) */
지역?: string | null;
상하차?: string | null;
}
export interface LogicOne {
file: string;
version: string;
logic: LogicRow;
blocked: boolean;
reasons: string[];
}
export interface CalcLine {
이름: string;
단위: string;
수량: number;
단가: number;
금액: number;
비목: Record<string, number>;
/** 값 없는 요소를 다른 값으로 셈 — 「준용: <직종>」 · 「산정: …」 */
출처?: string;
/** 자재 단위가 줄 단위와 성격이 달라 환산 못 하고 셈 — 「줄 m · 자재 Ton」 */
단위경고?: string;
/** 재료 줄이 잡은 품목 — 키 · 이름 · 규격 · 단위 · 값 칸 */
품목?: { 키: string; 이름?: string; 규격?: string; 단위?: string; 값칸?: string };
/** % 덧줄(149-4 · 서버 `M02_Labor_Doc.pct_extras`) — 율 · 밑수 글(「노무비의 %」 · 복합 = 빈 글) */
율?: number;
규격?: string;
/** 못 셈 줄(725 · M02 단가산출) — 금액 없음 까닭 */
까닭?: string;
/** (M02 744-1) 둘째 기초 세부 줄 — `수량`은 M01 원문 · 이 칸은 1 기준단위 몫 비목(금액 · 비목은 머리 수량 곱한 상자 몫) */
원문?: { 비목?: Record<string, number | null> };
/** (753-1) 옵션으로 빠진 줄 — 화면은 안 그림 */
옵션꺼짐?: boolean;
/** (796-2d) 엔진이 합계에서 빼는 줄(합밖 · 제외 단계) — 보이되 소계 · 합계에 안 더함 */
합밖?: boolean;
}
/** % 덧줄 표기(149-4) — 율 있으면 수량 = 율 · 단위 % · 이름 뒤 규격 괄호 · 금액은 그대로(M01 · M02 한 벌) */
export const pctView = (
x: Pick<CalcLine, "이름" | "수량" | "단위" | "율" | "규격">,
): { name: string; qty: number; unit: string } =>
x.율 == null
? { name: x.이름, qty: x.수량, unit: x.단위 }
: { name: x.규격 ? `${x.이름} (${x.규격})` : x.이름, qty: x.율, unit: "%" };
export interface SubBrief {
name: string;
book: string | null;
details: string[];
}
export interface LogicFile {
file: string;
book: string;
chapter: string;
version: string;
}
export interface SaveChange {
op: "edit" | "add" | "delete";
key?: string;
row?: LogicRow;
}
export interface SaveFile {
file: string;
version: string;
changes: SaveChange[];
}
/** 서버가 준 몸과 상태 번호 — 409·422 는 몸(`detail`)을 화면이 풀어 보임 */
export class ApiError extends Error {
constructor(
public status: number,
public detail: unknown,
) {
super(typeof detail === "string" ? detail : JSON.stringify(detail));
}
}
/** 상세 부품이 부르는 길 앞머리(717-1) — 읽기(로직 · 요소 · 재료 · 표 · 줄) · 셈(`/calc` · `/text`)
* · 기본 = M01(`/m01` · 시스템 관리자) · M02 = `{ read: "/m02/logic-lib", calc: "/m02/logic-lib" }`(로그인) */
export interface LogicApiPaths {
read: string;
calc: string;
}
const M01_PATHS: LogicApiPaths = { read: "/m01", calc: "/m01" };
let paths = M01_PATHS;
/** 상세를 그리기 전에 한 번 — 안 넘기면 M01 길로 되돌림 · 저장 · 만들기 길은 늘 `/m01` */
export const setLogicApiPaths = (next?: LogicApiPaths): void => {
paths = next ?? M01_PATHS;
};
export const logicApiPaths = (): LogicApiPaths => paths;
async function request<T>(path: string, body?: unknown, base = "/m01"): Promise<T> {
const response = await fetch(`${API_BASE_URL}${base}${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;
}
const query = (params: Record<string, string>): string => new URLSearchParams(params).toString();
export const fetchLogics = (): Promise<LogicSummary[]> =>
request<{ logics: LogicSummary[] }>("/logics", undefined, paths.read).then((d) => d.logics);
/** 왼쪽 트리 목록 — 서버가 준 구분·상세구분(장 차례대로) */
export const fetchLogicSubs = (): Promise<SubBrief[]> =>
request<{ subs: SubBrief[] }>(`/subs?${query({ group: "로직" })}`, undefined, paths.read).then(
(d) => d.subs,
);
export const fetchLogic = (key: string): Promise<LogicOne> =>
request(`/logic?${query({ key })}`, undefined, paths.read);
export const fetchLogicFiles = (): Promise<LogicFile[]> =>
request<{ files: LogicFile[] }>(`/groups/${encodeURIComponent("로직")}/files`).then(
(d) => d.files,
);
export const searchElements = (
group: string,
q: string,
): Promise<{ total: number; items: ElementBrief[] }> =>
request(`/elements?${query({ group, q, limit: "100" })}`, undefined, paths.read);
export const fetchMaterials = (cond: {
sub: string;
detail?: string;
spec?: string;
region?: string;
/** 호표 줄 단위 — 주면 그 단위 줄만 */
unit?: string;
}): Promise<{ total: number; 기본: string | null; items: ElementBrief[] }> =>
request(`/materials?${query({ ...cond, limit: "100" })}`, undefined, paths.read);
export const saveFiles = (
files: SaveFile[],
개정확인 = false,
): Promise<{ files: { file: string; version: string }[] }> => request("/save", { files, 개정확인 });
/** 로직을 부르는 곳(지우기 전 · 804-7) — 다른 수식 문서 · 일위대가 조합 · M02 단가산출 */
export const fetchLogicUsers = (key: string): Promise<{ 쓰는곳: string[] }> =>
request(`/logic/users?key=${encodeURIComponent(key)}`);
/** 로직 지우기(804-7) — 로직 줄 + 수식 문서 · 409 {쓰는곳} = 부르는 곳 있어 막음 · 409 {개정} = 정본 개정 확인 */
export const removeLogic = (
key: string,
file: string,
version: string,
개정확인 = false,
): Promise<unknown> => request("/logic/remove", { key, file, version, 개정확인 });
/** 본떠 만들기 = [복사/생성] — 원본 수식 문서를 새 자체 기초로 복제 · 새 키(`GX…`)는 서버가 줌(855 L3 ⓐ) ·
* 이름 · 원문번호 · 결과단위 · 출처 = 기본정보 창 값(빈 글 = 원본 그대로) */
export const copyLogic = (
key: string,
info: { 이름: string; 원문번호: string; 결과단위: string; 출처: string },
): Promise<{ file: string; version: string; key: string; logic: LogicRow }> =>
request("/logic/copy", { key, ...info });