/* ============================================================================= * M02_MyMaterial_Api.ts * M02 내 재료(개인 자재 PM · PLAN 840-4) 서버 호출 — 개인 층만 · 서버 `M02_MyMachine_Router` 의 /layers/personal/materials * (길 = 내 기계와 한 함수 `shelfPath` · 858 5-6) * 목록(줄마다 쓰는 곳 + 파일 판) · 만들기 · 고치기(연 판 · 다르면 409 `StaleError`) · 지우기(쓰는 곳 있으면 409) * · M01 재료 DB 와 같은 이름 · 규격 · 단위 = 409 * ========================================================================== */ import { call } from "./M02_MasterTemplete_Api_Fetch"; import { shelfPath } from "./M02_MyMachine_Api"; export interface MyMaterialUse { 종류: string; 키: string; 이름: string; } export interface MyMaterial { 키: string; 이름: string; 규격: string; 단위: string; 값: number | null; 쓰는곳?: MyMaterialUse[]; } export type MyMaterialBody = Pick; /** 목록 + 파일 판(고칠 때 보냄 · 858 5-6) */ export interface MyMaterialList { 줄: MyMaterial[]; 판?: string; } const path = (owner: string | null, key = ""): string => shelfPath("materials", owner, key ? `/${encodeURIComponent(key)}` : ""); export const listMyMaterials = (owner: string | null): Promise => call(path(owner)); export const addMyMaterial = (owner: string | null, body: MyMaterialBody): Promise => call(path(owner), { method: "POST", body: JSON.stringify(body) }); export const editMyMaterial = ( owner: string | null, key: string, body: MyMaterialBody, ver?: string, ): Promise => call(path(owner, key), { method: "PUT", body: JSON.stringify({ ...body, 판: ver ?? null }), }); export const dropMyMaterial = (owner: string | null, key: string): Promise => call(path(owner, key), { method: "DELETE" });