기간 필터링 추가
This commit is contained in:
@@ -547,4 +547,93 @@ export class DashboardController {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 테이블 스키마 조회 (날짜 컬럼 감지용)
|
||||
* POST /api/dashboards/table-schema
|
||||
*/
|
||||
async getTableSchema(
|
||||
req: AuthenticatedRequest,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const { tableName } = req.body;
|
||||
|
||||
if (!tableName || typeof tableName !== "string") {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: "테이블명이 필요합니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 테이블명 검증 (SQL 인젝션 방지)
|
||||
if (!/^[a-z_][a-z0-9_]*$/i.test(tableName)) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
message: "유효하지 않은 테이블명입니다.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// PostgreSQL information_schema에서 컬럼 정보 조회
|
||||
const query = `
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
udt_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = $1
|
||||
ORDER BY ordinal_position
|
||||
`;
|
||||
|
||||
const result = await PostgreSQLService.query(query, [
|
||||
tableName.toLowerCase(),
|
||||
]);
|
||||
|
||||
// 날짜/시간 타입 컬럼 필터링
|
||||
const dateColumns = result.rows
|
||||
.filter((row: any) => {
|
||||
const dataType = row.data_type?.toLowerCase();
|
||||
const udtName = row.udt_name?.toLowerCase();
|
||||
return (
|
||||
dataType === "timestamp" ||
|
||||
dataType === "timestamp without time zone" ||
|
||||
dataType === "timestamp with time zone" ||
|
||||
dataType === "date" ||
|
||||
dataType === "time" ||
|
||||
dataType === "time without time zone" ||
|
||||
dataType === "time with time zone" ||
|
||||
udtName === "timestamp" ||
|
||||
udtName === "timestamptz" ||
|
||||
udtName === "date" ||
|
||||
udtName === "time" ||
|
||||
udtName === "timetz"
|
||||
);
|
||||
})
|
||||
.map((row: any) => row.column_name);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
tableName,
|
||||
columns: result.rows.map((row: any) => ({
|
||||
name: row.column_name,
|
||||
type: row.data_type,
|
||||
udtName: row.udt_name,
|
||||
})),
|
||||
dateColumns,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: "테이블 스키마 조회 중 오류가 발생했습니다.",
|
||||
error:
|
||||
process.env.NODE_ENV === "development"
|
||||
? (error as Error).message
|
||||
: "스키마 조회 오류",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user