Files
Aislo/B05_Profile/B05_Profile_Api_RouteInitial.ts
T
eomsangdonandClaude Opus 5.5 4366cd3f03 fix(B05): 초기노선 갈래 화면을 서버 길 모양(PLAN 20장 API 줄)에 맞춤
- 요청 { mode, weights?{expected, earthwork, grade} } — logic · slope 가정을 버림
- 비교값 avg_grade_pct · over_limit.total · offset_avg_m, 기준값 pending(비면 확정) 읽기
- [확인] 몸통 initial 도 { mode, weights }
- 시험 test_b05_routeedit_initial.py 를 서버 답 모양으로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015sCeZz8z8YnbovsKgn7HK7
2026-09-29 10:03:38 +09:00

55 lines
2.2 KiB
TypeScript

/* =============================================================================
* B05_Profile_Api_RouteInitial.ts
* 초기노선 갈래 요청(계획서 20) — 로직 하나를 골라 서버가 새 계획노선 노드를 낸다.
*
* POST /projects/{id}/route/initial { mode, weights? } → 노드 · 비교값 · 공통 제약 기준값
*
* 계산 자리는 **서버 단독**(CLAUDE.md 5장 ③) — 화면은 부르고, 받은 노드를 편집 캐시에 싣고,
* 받은 비교값·기준값을 보이기만 한다. 모양은 계획서 20 「API」 줄(서버 `initial_route`) —
* 답을 펴는 자리는 `normalizeRouteInitial`(`_RouteEdit_Initial_Model`) 한 곳이다.
* ========================================================================== */
import { requestJson } from "./B05_Profile_Api_Replan";
/** 갈래 셈 대기 상한 — 노선 여러 벌을 셈해 견주므로 넉넉히 잡는다. */
const INITIAL_TIMEOUT_MS = 5 * 60 * 1000;
/** 로직 이름 — 서버와 같은 낱말을 쓴다. `follow` 는 예상노선 추종(처음 초기값). */
export type RouteInitialLogic = "follow" | "earthwork" | "gentle" | "weighted";
/** 비중 계산의 세 비중(%) — 합 100. */
export interface RouteInitialWeights {
expected: number;
earthwork: number;
grade: number;
}
export interface RouteInitialRequest {
mode: RouteInitialLogic;
weights?: RouteInitialWeights;
}
/** 서버 길이 아직 없다(404·405) — 화면은 이 글로 알린다. */
export const ROUTE_INITIAL_MISSING =
"초기노선 갈래 서버 길이 아직 없습니다(계획서 20 · sub3 대기).";
/** 로직 하나로 초기노선을 묻는다. 답의 모양은 `normalizeRouteInitial` 이 편다. */
export async function fetchRouteInitial(
projectId: string,
request: RouteInitialRequest,
): Promise<unknown> {
try {
return await requestJson<unknown>(
`/projects/${projectId}/route/initial`,
{ method: "POST", body: JSON.stringify(request) },
INITIAL_TIMEOUT_MS,
);
} catch (error) {
const message = error instanceof Error ? error.message : "";
if (/HTTP 40[45]|Not Found|Method Not Allowed/.test(message)) {
throw new Error(ROUTE_INITIAL_MISSING);
}
throw error;
}
}