/* ============================================================================= * M02_MyMaterial_Api.ts * M02 내 재료(개인 자재 PM · PLAN 840-4) 서버 호출 — 개인 층만 · 서버 `M02_Labor_Router` 의 /layers/personal/materials * 목록(줄마다 쓰는 곳) · 만들기 · 고치기 · 지우기(쓰는 곳 있으면 409) · M01 재료 DB 와 같은 이름 · 규격 · 단위 = 409 * ========================================================================== */ import { call } from "./M02_MasterTemplete_Api_Fetch"; export interface MyMaterialUse { 종류: string; 키: string; 이름: string; } export interface MyMaterial { 키: string; 이름: string; 규격: string; 단위: string; 값: number | null; 쓰는곳?: MyMaterialUse[]; } export type MyMaterialBody = Pick; const path = (owner: string | null, key = ""): string => `/layers/personal/materials${key ? `/${encodeURIComponent(key)}` : ""}${ owner ? `?owner=${encodeURIComponent(owner)}` : "" }`; export const listMyMaterials = (owner: string | null): Promise => call<{ 줄: MyMaterial[] }>(path(owner)).then((d) => d.줄); 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, ): Promise => call(path(owner, key), { method: "PUT", body: JSON.stringify(body) }); export const dropMyMaterial = (owner: string | null, key: string): Promise => call(path(owner, key), { method: "DELETE" });