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

189 lines
5.0 KiB
TypeScript
Raw Normal View History

2025-09-05 16:19:31 +09:00
import { apiClient, ApiResponse } from "./client";
2025-09-05 18:00:18 +09:00
// 테이블 간 데이터 관계 설정 관련 타입 정의
2025-09-05 16:19:31 +09:00
export interface ColumnInfo {
columnName: string;
columnLabel?: string;
displayName?: string;
dataType?: string;
dbType?: string;
webType?: string;
isNullable?: string;
columnDefault?: string;
characterMaximumLength?: number;
numericPrecision?: number;
numericScale?: number;
detailSettings?: string;
codeCategory?: string;
referenceTable?: string;
referenceColumn?: string;
isVisible?: string;
displayOrder?: number;
description?: string;
}
2025-09-05 18:00:18 +09:00
export interface TableDefinition {
tableName: string;
displayName?: string;
description?: string;
columns: ColumnInfo[];
2025-09-05 16:19:31 +09:00
}
2025-09-05 18:00:18 +09:00
export interface TableInfo {
tableName: string;
displayName: string;
description: string;
columnCount: number;
}
export interface TableRelationship {
2025-09-05 16:19:31 +09:00
relationshipId?: number;
relationshipName: string;
2025-09-05 18:00:18 +09:00
fromTableName: string;
fromColumnName: string;
toTableName: string;
toColumnName: string;
2025-09-05 16:19:31 +09:00
relationshipType: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
connectionType: "simple-key" | "data-save" | "external-call";
settings?: Record<string, any>;
companyCode: string;
isActive?: string;
}
2025-09-05 18:00:18 +09:00
// 테이블 간 데이터 관계 설정 API 클래스
2025-09-05 16:19:31 +09:00
export class DataFlowAPI {
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
2025-09-05 18:00:18 +09:00
static async getTables(): Promise<TableInfo[]> {
2025-09-05 16:19:31 +09:00
try {
2025-09-05 18:00:18 +09:00
const response = await apiClient.get<ApiResponse<TableInfo[]>>("/table-management/tables");
2025-09-05 16:19:31 +09:00
if (!response.data.success) {
2025-09-05 18:00:18 +09:00
throw new Error(response.data.message || "테이블 목록 조회에 실패했습니다.");
2025-09-05 16:19:31 +09:00
}
return response.data.data || [];
} catch (error) {
2025-09-05 18:00:18 +09:00
console.error("테이블 목록 조회 오류:", error);
2025-09-05 16:19:31 +09:00
throw error;
}
}
/**
*
*/
static async getTableColumns(tableName: string): Promise<ColumnInfo[]> {
try {
const response = await apiClient.get<ApiResponse<ColumnInfo[]>>(`/table-management/tables/${tableName}/columns`);
if (!response.data.success) {
throw new Error(response.data.message || "컬럼 정보 조회에 실패했습니다.");
}
return response.data.data || [];
} catch (error) {
console.error("컬럼 정보 조회 오류:", error);
throw error;
}
}
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
2025-09-05 18:00:18 +09:00
static async getTableWithColumns(tableName: string): Promise<TableDefinition | null> {
2025-09-05 16:19:31 +09:00
try {
2025-09-05 18:00:18 +09:00
const columns = await this.getTableColumns(tableName);
2025-09-05 16:19:31 +09:00
return {
2025-09-05 18:00:18 +09:00
tableName,
displayName: tableName,
description: `${tableName} 테이블`,
columns,
2025-09-05 16:19:31 +09:00
};
} catch (error) {
2025-09-05 18:00:18 +09:00
console.error("테이블 및 컬럼 정보 조회 오류:", error);
2025-09-05 16:19:31 +09:00
throw error;
}
}
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
2025-09-05 18:00:18 +09:00
static async createRelationship(relationship: Omit<TableRelationship, "relationshipId">): Promise<TableRelationship> {
2025-09-05 16:19:31 +09:00
try {
2025-09-05 18:00:18 +09:00
const response = await apiClient.post<ApiResponse<TableRelationship>>("/table-relationships", relationship);
2025-09-05 16:19:31 +09:00
if (!response.data.success) {
throw new Error(response.data.message || "관계 생성에 실패했습니다.");
}
return response.data.data!;
} catch (error) {
console.error("관계 생성 오류:", error);
throw error;
}
}
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
2025-09-05 18:00:18 +09:00
static async getRelationshipsByCompany(companyCode: string): Promise<TableRelationship[]> {
2025-09-05 16:19:31 +09:00
try {
2025-09-05 18:00:18 +09:00
const response = await apiClient.get<ApiResponse<TableRelationship[]>>("/table-relationships", {
2025-09-05 16:19:31 +09:00
params: { companyCode },
});
if (!response.data.success) {
throw new Error(response.data.message || "관계 목록 조회에 실패했습니다.");
}
return response.data.data || [];
} catch (error) {
console.error("관계 목록 조회 오류:", error);
throw error;
}
}
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
static async updateRelationship(
relationshipId: number,
2025-09-05 18:00:18 +09:00
relationship: Partial<TableRelationship>,
): Promise<TableRelationship> {
2025-09-05 16:19:31 +09:00
try {
2025-09-05 18:00:18 +09:00
const response = await apiClient.put<ApiResponse<TableRelationship>>(
`/table-relationships/${relationshipId}`,
2025-09-05 16:19:31 +09:00
relationship,
);
if (!response.data.success) {
throw new Error(response.data.message || "관계 수정에 실패했습니다.");
}
return response.data.data!;
} catch (error) {
console.error("관계 수정 오류:", error);
throw error;
}
}
/**
2025-09-05 18:00:18 +09:00
*
2025-09-05 16:19:31 +09:00
*/
static async deleteRelationship(relationshipId: number): Promise<void> {
try {
2025-09-05 18:00:18 +09:00
const response = await apiClient.delete<ApiResponse<null>>(`/table-relationships/${relationshipId}`);
2025-09-05 16:19:31 +09:00
if (!response.data.success) {
throw new Error(response.data.message || "관계 삭제에 실패했습니다.");
}
} catch (error) {
console.error("관계 삭제 오류:", error);
throw error;
}
}
}