refactor(856-4): 거꾸로 부름 끊기 본문 — 앞 커밋(bd41d8799)은 이름 옮김만 담김 · 이 커밋과 한 묶음
- 앞 커밋 글 그대로(층 · 부름 common_util_m02_call · 찾아 넣기 창 StackFind 주입 · 단위 고르기 부품 상자 · 합계 상자 A00 · 기계 칸 부품) - 앞 커밋에서 git add 가 옛 경로에 걸려 고친 파일이 빠짐 — 두 커밋을 같이 올림 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
* 마스터 템플릿 서버 호출 — 계약 `6_계약.md` 서버 길 · 시스템 층은 시스템 관리자만
|
||||
* ========================================================================== */
|
||||
|
||||
import { API_BASE_URL } from "@config/config_frontend";
|
||||
import { call, type Layer } from "../common_util/common_util_m02_call";
|
||||
|
||||
/** 층 이름 — 서버와 같은 글 */
|
||||
export type Layer = "system" | "company" | "personal" | "project";
|
||||
// 층 이름 · `/api/m02` 부름 = 공용 조각(856-4 — 줄 쌓기 공용 화면도 씀) · 여기서 그대로 내보냄
|
||||
export { call, StaleError, type Layer } from "../common_util/common_util_m02_call";
|
||||
/** 서버 종류 — 화면의 「표 양식」 = table · 「도면 양식」 = drawing · 「구조물 도면」 = structure ·
|
||||
* 「면적산출」 = area(구조물집계표 열마다 한 통합문서) ·
|
||||
* 「일위대가」 = labor(열마다 문서 · 39장) ·
|
||||
@@ -31,42 +31,6 @@ export interface TemplateDoc {
|
||||
문서: unknown;
|
||||
}
|
||||
|
||||
/** 서버가 판 불일치로 막았을 때 · `detail` = 서버 몸 그대로(729-3 `{까닭, 남은줄}`) */
|
||||
export class StaleError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
readonly detail?: unknown,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/** `/api/m02` 아래 길 부름 — 409 = StaleError · 그 밖 실패 = 서버 까닭 글(하위 폴더도 씀) */
|
||||
export async function call<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
const response = await fetch(`${API_BASE_URL}/m02${path}`, {
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
...init,
|
||||
});
|
||||
const body = (await response.json().catch(() => ({}))) as { detail?: unknown } & T;
|
||||
if (response.status === 409)
|
||||
throw new StaleError(reason(body.detail, response.status), body.detail);
|
||||
if (!response.ok) throw new Error(reason(body.detail, response.status));
|
||||
return body;
|
||||
}
|
||||
|
||||
/** 서버가 막은 까닭 그대로 — 문장 · `{errors: [...]}` · 입력 검사 목록(`[{msg}]`) */
|
||||
function reason(detail: unknown, status: number): string {
|
||||
if (typeof detail === "string") return detail;
|
||||
const why = (detail as { 까닭?: unknown } | null)?.까닭;
|
||||
if (typeof why === "string") return why;
|
||||
const list = Array.isArray(detail) ? detail : (detail as { errors?: unknown } | null)?.errors;
|
||||
const lines = Array.isArray(list)
|
||||
? list.map((x) => (typeof x === "string" ? x : String((x as { msg?: unknown })?.msg ?? "")))
|
||||
: [];
|
||||
return lines.filter(Boolean).join(" · ") || `HTTP ${status}`;
|
||||
}
|
||||
|
||||
/** 지금 화면의 층 — 시스템 · 회사 · 개인 모두 `/layers/{층}` 아래(구조물집계표 · 조합 길 모두 · 읽기는
|
||||
* 로그인 누구나 · 쓰기는 서버 층 권한 · 옛 `/api/m02/templates/*` 는 시스템 관리자 전용이라 안 씀) ·
|
||||
* `owner` = 남의 층을 볼 때 주인(회사 `{C}` · 개인 `{C}/{U}` · 자기 층 = null · PLAN 27-1c) —
|
||||
|
||||
Reference in New Issue
Block a user