Files
Aislo/M02_MasterTemplete/M02_MyMachine_Api.ts
T
eomsangdonandClaude Opus 5.5 c030ed24a7 refactor(858 5-6): 내 기계 · 내 재료를 서고 틀로 — 종류 표 · 층 번호 장부 · 내 재료 판 · 길 한 묶음
- 종류 표 `Template_Layers.SHELF`(자리 · 머리 · 이름 · 번호 · 나무) — LIBRARY_KINDS · Labor_Ref PREFIX · TITLE · 내 기계 · 내 재료 자리 · 머리를 표에서 읽음
- 내 기계 번호 = 층 `_번호.json` 「내기계」 칸(Labor_Ref.issued · keep_issued 공개) · 지운 끝 번호 안 다시 씀 · 옛 `_다음.json` · 옛 `내기계.json` 옮김(_move · _read) 걷음(요구 899 — 옛 꼴 호환 없음)
- 내 기계 잠금 = store._LOCK 한 벌(RLock) — 번호 장부를 SK · SC 와 같이 쓰므로 두 잠금 순서 교착 막음
- 내 재료 = 한 파일 + 판(version) · 고칠 때 옛 판 409 {stale, 판, 까닭} · 목록 답에 판
- 내 재료 길 넷을 Labor_Router → MyMachine_Router(길 글자 그대로 · openapi 묶음 이름만 바뀜)
- 화면 Api 「종류 + 층」 한 함수 shelfPath(내 기계 · 내 재료 · 찾기 · 내 품목) · Material_Pick 은 내 재료 Api 부름 · 내 재료 화면이 판을 보내고 409 면 다시 읽음
- 시험: 854_1 번호 장부 · 내 기계 지운 끝 번호 · material_own 판 409 새 시험 · 826_2 ③(옛 파일 옮김 = 죽은 코드만 붙듦) 지움 · material_own 화면 소스 글자 시험 지움(글자 시험 규칙) · shelf golden 다시 뜸(고치기 전 답과 통째 대조 — 다름 = 내 재료 목록 판 칸 하나 · 뒤 차례 번호 밀림)

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

200 lines
6.4 KiB
TypeScript

/* =============================================================================
* M02_MyMachine_Api.ts
* M02 내 기계 · 내 품목 서버 호출(PLAN 821-3) — 개인 층만.
* 내 기계 = `/layers/personal/my-machines`(821-1 · `M02_MyMachine_Router`) — 목록 · 하나 · 만들기 · 고치기 · 지우기
* 양식 목록 · 비슷한 기계 찾기 · 내 품목 = `M02_MyMachine_Look`(읽기만)
* 길 = 「종류 + 층」 한 함수 `shelfPath`(858 5-6 · 내 재료 `M02_MyMaterial_Api` 도 씀)
* ========================================================================== */
import type { MachinePick, MachineValues } from "../common_util/common_util_machine_sheet";
import { call, type Layer } from "./M02_MasterTemplete_Api_Fetch";
import type { M01Element } from "./M02_MasterTemplete_Find_Pick";
export type MachineHow = "바로" | "품셈" | "직접";
type Costs = Record<"노무비" | "재료비" | "경비", number>;
/** 서버 시간당 셈 답 — ok 아님 = 까닭 */
export interface MyHourly extends Partial<Costs> {
ok: boolean;
계?: number;
로직?: string | null;
직접?: boolean;
reason?: string;
}
/** 내 기계 줄(저장 꼴) */
export interface MyMachine {
키: string;
원문번호: string;
이름: string;
규격: string;
방식: MachineHow;
값: MachineValues;
시간당?: Costs;
비고?: string;
넣은날: string;
고친날: string;
본뜬?: string;
}
export interface MyMachineRow extends Omit<MyMachine, "시간당"> {
시간당: MyHourly;
쓰는곳수: number;
}
export interface Use {
키: string;
이름: string;
}
export interface MyMachineOne {
줄: MyMachine;
/** 연 판(854-1) — 고치기 때 보냄 · 다르면 409(`StaleError`) */
판?: string;
시간당: MyHourly;
같은이름: { 키: string; 이름: string; 규격: string; 출처: string }[];
쓰는곳?: Use[];
}
/** 보내는 줄 — 방식 · 값 또는 시간당(직접) */
export interface MyMachineBody {
이름: string;
규격: string;
방식: MachineHow;
값?: MachineValues;
시간당?: Partial<Costs>;
}
export interface MachineLists {
fuels: MachinePick[];
jobs: MachinePick[];
power: number;
hour: number;
}
export interface SimilarRow {
키: string;
원문번호?: string;
이름: string;
규격: string;
구분: string;
값?: MachineValues;
방식?: MachineHow;
시간당?: Costs;
출처: "개인" | "M01";
}
export interface MyItem {
이름: string;
규격: string;
단위: string;
값: unknown;
쓰는곳: Use[];
}
/** 내 기계 · 내 재료 길 종류(서버 `M02_MyMachine_Router` · `M02_MyMachine_Look`) */
export type ShelfKind = "my-machines" | "materials" | "my-machine-find" | "my-items";
/** 「종류 + 층」 길 한 함수 — `owner` = 남의 층(없으면 내 층) · `tail` = `/키` 등 · 층 = 지금은 개인 층만 */
export const shelfPath = (
kind: ShelfKind,
owner: string | null,
tail = "",
q: Record<string, string> = {},
layer: Layer = "personal",
): string => {
const ask = new URLSearchParams({ ...q, ...(owner ? { owner } : {}) }).toString();
return `/layers/${layer}/${kind}${tail}${ask ? `?${ask}` : ""}`;
};
const at = (owner: string | null, tail = ""): string => shelfPath("my-machines", owner, tail);
const key = (k: string): string => `/${encodeURIComponent(k)}`;
export const listMyMachines = async (owner: string | null): Promise<MyMachineRow[]> =>
(await call<{ 줄: MyMachineRow[] }>(at(owner))).줄;
export const readMyMachine = (owner: string | null, k: string): Promise<MyMachineOne> =>
call(at(owner, key(k)));
export const createMyMachine = (
owner: string | null,
body: MyMachineBody,
base?: string,
): Promise<MyMachineOne> =>
call(at(owner), { method: "POST", body: JSON.stringify({ 줄: body, 본뜬: base ?? null }) });
export const updateMyMachine = (
owner: string | null,
k: string,
body: MyMachineBody,
ver?: string,
): Promise<MyMachineOne> =>
call(at(owner, key(k)), { method: "PUT", body: JSON.stringify({ 줄: body, 판: ver ?? null }) });
/** 저장 전 영향(848-5) — 바뀐 칸 · 이 층 쓰는 단가산출(그 칸을 따로 고쳐 둠?) · 쓰기 없음 */
export interface MyMachineImpact {
칸: string[];
쓰는곳: (Use & { 고침: boolean; 위층: boolean })[];
고침: number;
위층: number;
}
export const impactMyMachine = (
owner: string | null,
k: string,
body: MyMachineBody,
): Promise<MyMachineImpact> =>
call(at(owner, `${key(k)}/impact`), { method: "POST", body: JSON.stringify({ 줄: body }) });
export const deleteMyMachine = (owner: string | null, k: string): Promise<{ 쓰는곳: Use[] }> =>
call(at(owner, key(k)), { method: "DELETE" });
let lists: Promise<MachineLists> | null = null;
/** 양식 고르기 목록 — 한 번 받아 둠 */
export const fetchMyMachineLists = (): Promise<MachineLists> =>
(lists ??= call<MachineLists>("/my-machine-lists").catch((e) => {
lists = null;
return Promise.reject(e);
}));
export const findSimilar = async (owner: string | null, q: string): Promise<SimilarRow[]> =>
(await call<{ rows: SimilarRow[] }>(shelfPath("my-machine-find", owner, "", { q }))).rows;
export const listMyItems = async (owner: string | null): Promise<MyItem[]> =>
(await call<{ rows: MyItem[] }>(shelfPath("my-items", owner))).rows;
/** 단가산출 줄 기계 입력 글(줄 쌓기 `기계='개인 EQP…'`) */
export const machineArg = (no: string): string => `'${no}'`;
/** 내 기계 → 기계 고르기 한 줄(`M01Element` 꼴 · 줄 쌓기 = 로직 + 기계='개인 EQP…') */
export const mineElement = (
row: Pick<MyMachine, "키" | "원문번호" | "이름" | "규격">,
h: MyHourly,
): M01Element => ({
종류: "기계",
코드: row.키,
이름: row.이름,
규격: row.규격,
단위: "시간",
값: h.ok ? (h.계 ?? null) : null,
단가: { 노무비: h.노무비 ?? 0, 재료비: h.재료비 ?? 0, 경비: h.경비 ?? 0 },
로직: h.로직 ?? undefined,
원문번호: row.원문번호,
});
/** M01 기계 줄 값 + 시간당(기계 창 목록 · 양식 · 60 까지) */
export interface MachineBrief {
키: string;
원문번호: string;
이름: string;
규격: string;
값: MachineValues;
시간당: MyHourly;
}
export const machineRows = async (keys: string[]): Promise<MachineBrief[]> =>
keys.length
? (
await call<{ rows: MachineBrief[] }>(
`/logic-lib/machine-rows?keys=${encodeURIComponent(keys.join(","))}`,
)
).rows
: [];