Merge branch 'dev' of http://39.117.244.52:3000/kjs/ERP-node into feature/screen-management
This commit is contained in:
@@ -30,6 +30,7 @@ import componentStandardRoutes from "./routes/componentStandardRoutes";
|
||||
import layoutRoutes from "./routes/layoutRoutes";
|
||||
import dataRoutes from "./routes/dataRoutes";
|
||||
import testButtonDataflowRoutes from "./routes/testButtonDataflowRoutes";
|
||||
import externalDbConnectionRoutes from "./routes/externalDbConnectionRoutes";
|
||||
// import userRoutes from './routes/userRoutes';
|
||||
// import menuRoutes from './routes/menuRoutes';
|
||||
|
||||
@@ -123,6 +124,7 @@ app.use("/api/layouts", layoutRoutes);
|
||||
app.use("/api/screen", screenStandardRoutes);
|
||||
app.use("/api/data", dataRoutes);
|
||||
app.use("/api/test-button-dataflow", testButtonDataflowRoutes);
|
||||
app.use("/api/external-db-connections", externalDbConnectionRoutes);
|
||||
// app.use('/api/users', userRoutes);
|
||||
// app.use('/api/menus', menuRoutes);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ router.put(
|
||||
|
||||
/**
|
||||
* DELETE /api/external-db-connections/:id
|
||||
* 외부 DB 연결 삭제 (논리 삭제)
|
||||
* 외부 DB 연결 삭제 (물리 삭제)
|
||||
*/
|
||||
router.delete(
|
||||
"/:id",
|
||||
@@ -207,6 +207,63 @@ router.delete(
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* POST /api/external-db-connections/test
|
||||
* 데이터베이스 연결 테스트
|
||||
*/
|
||||
router.post(
|
||||
"/test",
|
||||
authenticateToken,
|
||||
async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const testData =
|
||||
req.body as import("../types/externalDbTypes").ConnectionTestRequest;
|
||||
|
||||
// 필수 필드 검증
|
||||
const requiredFields = [
|
||||
"db_type",
|
||||
"host",
|
||||
"port",
|
||||
"database_name",
|
||||
"username",
|
||||
"password",
|
||||
];
|
||||
const missingFields = requiredFields.filter(
|
||||
(field) => !testData[field as keyof typeof testData]
|
||||
);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
message: "필수 필드가 누락되었습니다.",
|
||||
error: {
|
||||
code: "MISSING_FIELDS",
|
||||
details: `다음 필드가 필요합니다: ${missingFields.join(", ")}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const result = await ExternalDbConnectionService.testConnection(testData);
|
||||
|
||||
return res.status(200).json({
|
||||
success: result.success,
|
||||
data: result,
|
||||
message: result.message,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("연결 테스트 오류:", error);
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
message: "연결 테스트 중 서버 오류가 발생했습니다.",
|
||||
error: {
|
||||
code: "SERVER_ERROR",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* GET /api/external-db-connections/types/supported
|
||||
* 지원하는 DB 타입 목록 조회
|
||||
|
||||
@@ -279,7 +279,7 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 외부 DB 연결 삭제 (논리 삭제)
|
||||
* 외부 DB 연결 삭제 (물리 삭제)
|
||||
*/
|
||||
static async deleteConnection(id: number): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
@@ -295,13 +295,9 @@ export class ExternalDbConnectionService {
|
||||
};
|
||||
}
|
||||
|
||||
// 논리 삭제 (is_active를 'N'으로 변경)
|
||||
await prisma.external_db_connections.update({
|
||||
// 물리 삭제 (실제 데이터 삭제)
|
||||
await prisma.external_db_connections.delete({
|
||||
where: { id },
|
||||
data: {
|
||||
is_active: "N",
|
||||
updated_date: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -318,6 +314,185 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터베이스 연결 테스트
|
||||
*/
|
||||
static async testConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
switch (testData.db_type.toLowerCase()) {
|
||||
case "postgresql":
|
||||
return await this.testPostgreSQLConnection(testData, startTime);
|
||||
case "mysql":
|
||||
return await this.testMySQLConnection(testData, startTime);
|
||||
case "oracle":
|
||||
return await this.testOracleConnection(testData, startTime);
|
||||
case "mssql":
|
||||
return await this.testMSSQLConnection(testData, startTime);
|
||||
case "sqlite":
|
||||
return await this.testSQLiteConnection(testData, startTime);
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
message: `지원하지 않는 데이터베이스 타입입니다: ${testData.db_type}`,
|
||||
error: {
|
||||
code: "UNSUPPORTED_DB_TYPE",
|
||||
details: `${testData.db_type} 타입은 현재 지원하지 않습니다.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: "연결 테스트 중 오류가 발생했습니다.",
|
||||
error: {
|
||||
code: "TEST_ERROR",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL 연결 테스트
|
||||
*/
|
||||
private static async testPostgreSQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const { Client } = await import("pg");
|
||||
const client = new Client({
|
||||
host: testData.host,
|
||||
port: testData.port,
|
||||
database: testData.database_name,
|
||||
user: testData.username,
|
||||
password: testData.password,
|
||||
connectionTimeoutMillis: (testData.connection_timeout || 30) * 1000,
|
||||
ssl: testData.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
const result = await client.query(
|
||||
"SELECT version(), pg_database_size(current_database()) as size"
|
||||
);
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
await client.end();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "PostgreSQL 연결이 성공했습니다.",
|
||||
details: {
|
||||
response_time: responseTime,
|
||||
server_version: result.rows[0]?.version || "알 수 없음",
|
||||
database_size: this.formatBytes(
|
||||
parseInt(result.rows[0]?.size || "0")
|
||||
),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
try {
|
||||
await client.end();
|
||||
} catch (endError) {
|
||||
// 연결 종료 오류는 무시
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "PostgreSQL 연결에 실패했습니다.",
|
||||
error: {
|
||||
code: "CONNECTION_FAILED",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMySQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
// MySQL 라이브러리가 없으므로 모의 구현
|
||||
return {
|
||||
success: false,
|
||||
message: "MySQL 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "MySQL 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Oracle 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testOracleConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "Oracle 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "Oracle 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Server 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMSSQLConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQL Server 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "SQL Server 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testSQLiteConnection(
|
||||
testData: import("../types/externalDbTypes").ConnectionTestRequest,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQLite 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details:
|
||||
"SQLite는 파일 기반이므로 네트워크 연결 테스트가 불가능합니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 바이트 크기를 읽기 쉬운 형태로 변환
|
||||
*/
|
||||
private static formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
const k = 1024;
|
||||
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* 연결 데이터 검증
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,32 @@ export const ACTIVE_STATUS_OPTIONS = [
|
||||
{ value: "", label: "전체" },
|
||||
];
|
||||
|
||||
// 연결 테스트 관련 타입
|
||||
export interface ConnectionTestRequest {
|
||||
db_type: string;
|
||||
host: string;
|
||||
port: number;
|
||||
database_name: string;
|
||||
username: string;
|
||||
password: string;
|
||||
connection_timeout?: number;
|
||||
ssl_enabled?: string;
|
||||
}
|
||||
|
||||
export interface ConnectionTestResult {
|
||||
success: boolean;
|
||||
message: string;
|
||||
details?: {
|
||||
response_time?: number;
|
||||
server_version?: string;
|
||||
database_size?: string;
|
||||
};
|
||||
error?: {
|
||||
code?: string;
|
||||
details?: string;
|
||||
};
|
||||
}
|
||||
|
||||
// 연결 옵션 스키마 (각 DB 타입별 추가 옵션)
|
||||
export interface MySQLConnectionOptions {
|
||||
charset?: string;
|
||||
|
||||
Reference in New Issue
Block a user