한글뷰어 기능수정 Ver.01

This commit is contained in:
koj729
2026-06-19 17:58:47 +09:00
parent 9268e4e6bc
commit 83b6e891ab
49 changed files with 8741 additions and 446 deletions

View File

@@ -615,34 +615,63 @@ exports.deleteUser = async (req, res) => {
// 5. 활동 로그 조회 (Activity Logs)
exports.getAuditLogs = async (req, res) => {
const { user_id, activity, project_nm } = req.query;
let { user_id, activity, project_nm, page = 1, limit = 20 } = req.query;
page = parseInt(page);
limit = parseInt(limit);
const offset = (page - 1) * limit;
const client = await pool.connect();
try {
let countQuery = `
SELECT COUNT(*) as total
FROM ver4.${tbLog} l
LEFT JOIN ver4.${tbProject} p ON l.project_id = p.project_id
WHERE 1=1
`;
let query = `
SELECT l.log_id, l.log_date as clean_date, l.project_id, p.project_nm, l.user_id, l.user_ip, l.activity as clean_path, l.path_arr as criteria_info
FROM ver4.${tbLog} l
LEFT JOIN ver4.${tbProject} p ON l.project_id = p.project_id
WHERE 1=1
`;
const params = [];
const filterParams = [];
let paramIndex = 1;
let filterSql = '';
if (user_id) {
query += ` AND l.user_id ILIKE $${paramIndex++}`;
params.push(`%${user_id}%`);
filterSql += ` AND l.user_id ILIKE $${paramIndex++}`;
filterParams.push(`%${user_id}%`);
}
if (project_nm) {
query += ` AND (p.project_nm ILIKE $${paramIndex++} OR l.project_id ILIKE $${paramIndex - 1})`;
params.push(`%${project_nm}%`);
filterSql += ` AND (p.project_nm ILIKE $${paramIndex++} OR l.project_id ILIKE $${paramIndex - 1})`;
filterParams.push(`%${project_nm}%`);
}
if (activity && activity !== 'all') {
query += ` AND l.activity ILIKE $${paramIndex++}`;
params.push(`%${activity}%`);
filterSql += ` AND l.activity ILIKE $${paramIndex++}`;
filterParams.push(`%${activity}%`);
}
query += ` ORDER BY l.log_id DESC LIMIT 100;`;
const result = await client.query(query, params);
res.status(200).json(result.rows);
countQuery += filterSql;
query += filterSql;
const countResult = await client.query(countQuery, filterParams);
const total = parseInt(countResult.rows[0].total);
query += ` ORDER BY l.log_id DESC LIMIT $${paramIndex++} OFFSET $${paramIndex++};`;
const dataParams = [...filterParams, limit, offset];
const result = await client.query(query, dataParams);
res.status(200).json({
data: result.rows,
pagination: {
total,
page,
limit,
totalPages: Math.ceil(total / limit)
}
});
} catch (err) {
console.error("getAuditLogs Error:", err);
res.status(500).json({ error: "활동 로그 조회 실패" });