ERP-node/frontend/lib/api/nodeFlows.ts

123 lines
3.3 KiB
TypeScript

/**
* 노드 플로우 API
*/
import { apiClient } from "./client";
export interface NodeFlow {
flowId: number;
flowName: string;
flowDescription: string;
flowData: string | any; // JSONB는 문자열 또는 객체로 반환될 수 있음
createdAt: string;
updatedAt: string;
}
interface ApiResponse<T> {
success: boolean;
data?: T;
message?: string;
}
/**
* 플로우 목록 조회
*/
export async function getNodeFlows(): Promise<NodeFlow[]> {
const response = await apiClient.get<ApiResponse<NodeFlow[]>>("/dataflow/node-flows");
if (response.data.success && response.data.data) {
return response.data.data;
}
throw new Error(response.data.message || "플로우 목록을 불러올 수 없습니다.");
}
/**
* 플로우 상세 조회
*/
export async function getNodeFlow(flowId: number): Promise<NodeFlow> {
const response = await apiClient.get<ApiResponse<NodeFlow>>(`/dataflow/node-flows/${flowId}`);
if (response.data.success && response.data.data) {
return response.data.data;
}
throw new Error(response.data.message || "플로우를 불러올 수 없습니다.");
}
/**
* 플로우 저장 (신규)
*/
export async function createNodeFlow(data: {
flowName: string;
flowDescription: string;
flowData: string;
}): Promise<{ flowId: number }> {
const response = await apiClient.post<ApiResponse<{ flowId: number }>>("/dataflow/node-flows", data);
if (response.data.success && response.data.data) {
return response.data.data;
}
throw new Error(response.data.message || "플로우를 저장할 수 없습니다.");
}
/**
* 플로우 수정
*/
export async function updateNodeFlow(data: {
flowId: number;
flowName: string;
flowDescription: string;
flowData: string;
}): Promise<{ flowId: number }> {
const response = await apiClient.put<ApiResponse<{ flowId: number }>>("/dataflow/node-flows", data);
if (response.data.success && response.data.data) {
return response.data.data;
}
throw new Error(response.data.message || "플로우를 수정할 수 없습니다.");
}
/**
* 플로우 삭제
*/
export async function deleteNodeFlow(flowId: number): Promise<void> {
const response = await apiClient.delete<ApiResponse<void>>(`/dataflow/node-flows/${flowId}`);
if (!response.data.success) {
throw new Error(response.data.message || "플로우를 삭제할 수 없습니다.");
}
}
/**
* 플로우 실행
*/
export async function executeNodeFlow(flowId: number, contextData: Record<string, any>): Promise<ExecutionResult> {
const response = await apiClient.post<ApiResponse<ExecutionResult>>(
`/dataflow/node-flows/${flowId}/execute`,
contextData,
);
if (response.data.success && response.data.data) {
return response.data.data;
}
throw new Error(response.data.message || "플로우를 실행할 수 없습니다.");
}
/**
* 플로우 실행 결과 인터페이스
*/
export interface ExecutionResult {
success: boolean;
message: string;
executionTime: number;
nodes: NodeExecutionSummary[];
summary: {
total: number;
success: number;
failed: number;
skipped: number;
};
}
export interface NodeExecutionSummary {
nodeId: string;
nodeName: string;
nodeType: string;
status: "success" | "failed" | "skipped" | "pending";
duration?: number;
error?: string;
}