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

151 lines
4.2 KiB
TypeScript

import { apiClient, ApiResponse } from "./client";
// 외부 호출 설정 타입 정의
export interface ExternalCallConfig {
id?: number;
config_name: string;
call_type: string;
api_type?: string;
config_data: Record<string, unknown>;
description?: string;
company_code?: string;
is_active?: string;
created_date?: string;
created_by?: string;
updated_date?: string;
updated_by?: string;
}
export interface ExternalCallConfigFilter {
company_code?: string;
call_type?: string;
api_type?: string;
is_active?: string;
search?: string;
}
export interface ExternalCallConfigTestResult {
success: boolean;
message: string;
}
/**
* 외부 호출 설정 관리 API 클라이언트
*/
export class ExternalCallConfigAPI {
private static readonly BASE_URL = "/external-call-configs";
/**
* 외부 호출 설정 목록 조회
*/
static async getConfigs(filter?: ExternalCallConfigFilter): Promise<ApiResponse<ExternalCallConfig[]>> {
try {
const params = new URLSearchParams();
if (filter?.company_code) params.append("company_code", filter.company_code);
if (filter?.call_type) params.append("call_type", filter.call_type);
if (filter?.api_type) params.append("api_type", filter.api_type);
if (filter?.is_active) params.append("is_active", filter.is_active);
if (filter?.search) params.append("search", filter.search);
const url = params.toString() ? `${this.BASE_URL}?${params.toString()}` : this.BASE_URL;
const response = await apiClient.get(url);
return response.data;
} catch (error) {
console.error("외부 호출 설정 목록 조회 실패:", error);
throw error;
}
}
/**
* 외부 호출 설정 단일 조회
*/
static async getConfigById(id: number): Promise<ApiResponse<ExternalCallConfig>> {
try {
const response = await apiClient.get(`${this.BASE_URL}/${id}`);
return response.data;
} catch (error) {
console.error(`외부 호출 설정 조회 실패 (ID: ${id}):`, error);
throw error;
}
}
/**
* 외부 호출 설정 생성
*/
static async createConfig(
config: Omit<ExternalCallConfig, "id" | "created_date" | "updated_date">,
): Promise<ApiResponse<ExternalCallConfig>> {
try {
const response = await apiClient.post(this.BASE_URL, config);
return response.data;
} catch (error) {
console.error("외부 호출 설정 생성 실패:", error);
throw error;
}
}
/**
* 외부 호출 설정 수정
*/
static async updateConfig(id: number, config: Partial<ExternalCallConfig>): Promise<ApiResponse<ExternalCallConfig>> {
try {
const response = await apiClient.put(`${this.BASE_URL}/${id}`, config);
return response.data;
} catch (error) {
console.error(`외부 호출 설정 수정 실패 (ID: ${id}):`, error);
throw error;
}
}
/**
* 외부 호출 설정 삭제
*/
static async deleteConfig(id: number): Promise<ApiResponse<void>> {
try {
const response = await apiClient.delete(`${this.BASE_URL}/${id}`);
return response.data;
} catch (error) {
console.error(`외부 호출 설정 삭제 실패 (ID: ${id}):`, error);
throw error;
}
}
/**
* 외부 호출 설정 테스트
*/
static async testConfig(id: number): Promise<ApiResponse<ExternalCallConfigTestResult>> {
try {
const response = await apiClient.post(`${this.BASE_URL}/${id}/test`);
return response.data;
} catch (error) {
console.error(`외부 호출 설정 테스트 실패 (ID: ${id}):`, error);
throw error;
}
}
}
// 호출 타입 옵션
export const CALL_TYPE_OPTIONS = [
{ value: "rest-api", label: "REST API" },
{ value: "email", label: "이메일" },
{ value: "ftp", label: "FTP" },
{ value: "queue", label: "큐" },
];
// API 타입 옵션 (REST API 전용)
export const API_TYPE_OPTIONS = [
{ value: "discord", label: "Discord" },
{ value: "slack", label: "Slack" },
{ value: "kakao-talk", label: "카카오톡" },
{ value: "mattermost", label: "Mattermost" },
{ value: "generic", label: "기타 (일반 API)" },
];
// 활성화 상태 옵션
export const ACTIVE_STATUS_OPTIONS = [
{ value: "Y", label: "활성" },
{ value: "N", label: "비활성" },
];