feat: Integrate audit logging for various operations

- Added audit logging functionality across multiple controllers, including menu, user, department, flow, screen, and table management.
- Implemented logging for create, update, and delete actions, capturing relevant details such as company code, user information, and changes made.
- Enhanced the category tree service with a new endpoint to check if category values are in use, improving data integrity checks.
- Updated routes to include new functionalities and ensure proper logging for batch operations and individual record changes.
- This integration improves traceability and accountability for data modifications within the application.
This commit is contained in:
kjs
2026-03-04 13:49:08 +09:00
parent f04d224b09
commit b4d5367e2b
26 changed files with 2620 additions and 140 deletions

View File

@@ -9,6 +9,7 @@ import {
} from "../middleware/authMiddleware";
import { numberingRuleService } from "../services/numberingRuleService";
import { logger } from "../utils/logger";
import { auditLogService } from "../services/auditLogService";
const router = Router();
@@ -189,6 +190,19 @@ router.post(
menuObjid: newRule.menuObjid,
});
auditLogService.log({
companyCode,
userId,
action: "CREATE",
resourceType: "NUMBERING_RULE",
resourceId: String(newRule.ruleId),
resourceName: ruleConfig.ruleName,
summary: `채번 규칙 "${ruleConfig.ruleName}" 생성`,
changes: { after: { ruleName: ruleConfig.ruleName, prefix: ruleConfig.prefix } },
ipAddress: (req as any).ip,
requestPath: req.originalUrl,
});
return res.status(201).json({ success: true, data: newRule });
} catch (error: any) {
if (error.code === "23505") {
@@ -218,12 +232,29 @@ router.put(
logger.info("채번 규칙 수정 요청", { ruleId, companyCode, updates });
try {
const beforeRule = await numberingRuleService.getRuleById(ruleId, companyCode);
const updatedRule = await numberingRuleService.updateRule(
ruleId,
updates,
companyCode
);
logger.info("채번 규칙 수정 성공", { ruleId, companyCode });
auditLogService.log({
companyCode,
userId: req.user?.userId || "",
action: "UPDATE",
resourceType: "NUMBERING_RULE",
resourceId: ruleId,
summary: `채번 규칙(ID:${ruleId}) 수정`,
changes: {
before: { ruleName: beforeRule?.ruleName, prefix: beforeRule?.prefix },
after: updates,
},
ipAddress: (req as any).ip,
requestPath: req.originalUrl,
});
return res.json({ success: true, data: updatedRule });
} catch (error: any) {
logger.error("채번 규칙 수정 실패", {
@@ -250,6 +281,18 @@ router.delete(
try {
await numberingRuleService.deleteRule(ruleId, companyCode);
auditLogService.log({
companyCode,
userId: req.user?.userId || "",
action: "DELETE",
resourceType: "NUMBERING_RULE",
resourceId: ruleId,
summary: `채번 규칙(ID:${ruleId}) 삭제`,
ipAddress: (req as any).ip,
requestPath: req.originalUrl,
});
return res.json({ success: true, message: "규칙이 삭제되었습니다" });
} catch (error: any) {
if (error.message.includes("찾을 수 없거나")) {