94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
|
|
import { apiClient } from "./client";
|
||
|
|
|
||
|
|
export interface EntityReferenceOption {
|
||
|
|
value: string;
|
||
|
|
label: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface EntityReferenceData {
|
||
|
|
options: EntityReferenceOption[];
|
||
|
|
referenceInfo: {
|
||
|
|
referenceTable: string;
|
||
|
|
referenceColumn: string;
|
||
|
|
displayColumn: string | null;
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CodeReferenceData {
|
||
|
|
options: EntityReferenceOption[];
|
||
|
|
codeCategory: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ApiResponse<T> {
|
||
|
|
success: boolean;
|
||
|
|
message: string;
|
||
|
|
data?: T;
|
||
|
|
error?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export class EntityReferenceAPI {
|
||
|
|
/**
|
||
|
|
* 엔티티 참조 데이터 조회
|
||
|
|
*/
|
||
|
|
static async getEntityReferenceData(
|
||
|
|
tableName: string,
|
||
|
|
columnName: string,
|
||
|
|
options: {
|
||
|
|
limit?: number;
|
||
|
|
search?: string;
|
||
|
|
} = {},
|
||
|
|
): Promise<EntityReferenceData> {
|
||
|
|
try {
|
||
|
|
const params = new URLSearchParams();
|
||
|
|
if (options.limit) params.append("limit", options.limit.toString());
|
||
|
|
if (options.search) params.append("search", options.search);
|
||
|
|
|
||
|
|
const queryString = params.toString();
|
||
|
|
const url = `/entity-reference/${tableName}/${columnName}${queryString ? `?${queryString}` : ""}`;
|
||
|
|
|
||
|
|
const response = await apiClient.get<ApiResponse<EntityReferenceData>>(url);
|
||
|
|
|
||
|
|
if (!response.data.success || !response.data.data) {
|
||
|
|
throw new Error(response.data.message || "엔티티 참조 데이터 조회에 실패했습니다.");
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.data.data;
|
||
|
|
} catch (error) {
|
||
|
|
console.error("엔티티 참조 데이터 조회 오류:", error);
|
||
|
|
throw error instanceof Error ? error : new Error("엔티티 참조 데이터 조회 중 오류가 발생했습니다.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 공통 코드 데이터 조회
|
||
|
|
*/
|
||
|
|
static async getCodeReferenceData(
|
||
|
|
codeCategory: string,
|
||
|
|
options: {
|
||
|
|
limit?: number;
|
||
|
|
search?: string;
|
||
|
|
} = {},
|
||
|
|
): Promise<CodeReferenceData> {
|
||
|
|
try {
|
||
|
|
const params = new URLSearchParams();
|
||
|
|
if (options.limit) params.append("limit", options.limit.toString());
|
||
|
|
if (options.search) params.append("search", options.search);
|
||
|
|
|
||
|
|
const queryString = params.toString();
|
||
|
|
const url = `/entity-reference/code/${codeCategory}${queryString ? `?${queryString}` : ""}`;
|
||
|
|
|
||
|
|
const response = await apiClient.get<ApiResponse<CodeReferenceData>>(url);
|
||
|
|
|
||
|
|
if (!response.data.success || !response.data.data) {
|
||
|
|
throw new Error(response.data.message || "공통 코드 데이터 조회에 실패했습니다.");
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.data.data;
|
||
|
|
} catch (error) {
|
||
|
|
console.error("공통 코드 데이터 조회 오류:", error);
|
||
|
|
throw error instanceof Error ? error : new Error("공통 코드 데이터 조회 중 오류가 발생했습니다.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|