Files
Aislo/Z01_MasterData/Z01_MasterData_Api_Fetch.ts
T

64 lines
1.8 KiB
TypeScript

/* =============================================================================
* Z01_MasterData_Api_Fetch.ts
* 마스터 데이터 읽기 — 서버 `Z01_MasterData_Router.py`(랩탑 메인) · 시스템 관리자만
*
* 응답 모양은 2026-09-15 브레인이 못박은 약속 그대로. 읽기 전용 — 고치기는 다음 차례.
* ========================================================================== */
import { API_BASE_URL } from "@config/config_frontend";
import type { MasterColumn } from "./Z01_MasterData_UI_Cells";
export interface MasterTable {
id: string;
label: string;
key: string;
row_count: number;
}
export interface MasterFile {
id: string;
label: string;
key: string;
tables: MasterTable[];
}
export interface MasterGroup {
key: "logic" | "base" | "byproduct" | "seed";
label: string;
files: MasterFile[];
}
export interface MasterRows {
columns: MasterColumn[];
rows: Record<string, unknown>[];
total: number;
}
async function request<T>(path: string): Promise<T> {
const response = await fetch(`${API_BASE_URL}${path}`, { credentials: "include" });
const data = (await response.json()) as { detail?: string } & T;
if (!response.ok) throw new Error(data.detail ?? "Request failed");
return data;
}
export async function fetchMasterTree(): Promise<MasterGroup[]> {
return (await request<{ groups: MasterGroup[] }>("/master-data/tree")).groups;
}
export function fetchMasterRows(query: {
file: string;
table: string;
page: number;
size: number;
q: string;
}): Promise<MasterRows> {
const params = new URLSearchParams({
file: query.file,
table: query.table,
page: String(query.page),
size: String(query.size),
q: query.q,
});
return request<MasterRows>(`/master-data/rows?${params}`);
}