fix: 审计日志补充关键操作详情,前端改为可读格式显示

This commit is contained in:
selfrelease
2026-07-28 15:28:03 +08:00
parent 7716de63f1
commit 5aa7af9a46
4 changed files with 118 additions and 17 deletions
+54 -7
View File
@@ -98,7 +98,13 @@ router.post('/resignation', authMiddleware, async (req: AuthRequest, res, next)
router.delete('/:id/revoke', authMiddleware, async (req: AuthRequest, res, next) => {
try {
const result = await revokeTermination(req.user!.orgId, req.params.id)
await auditLog(req, 'REVOKE_TERMINATION', 'TERMINATION_RECORD', req.params.id, {})
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true, type: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true } }) : null
await auditLog(req, 'REVOKE_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
reason: termRecord?.reason || '',
type: termRecord?.type || '',
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'CONFLICT') {
@@ -183,7 +189,15 @@ router.get('/handover-template', authMiddleware, async (req: AuthRequest, res) =
router.post('/draft', authMiddleware, async (req: AuthRequest, res, next) => {
try {
const result = await createDraft(req.user!.orgId, req.user!.id, req.body)
await auditLog(req, 'CREATE_DRAFT', 'TERMINATION_RECORD', result.id, { reason: req.body.reason })
const emp = await prisma.employee.findFirst({ where: { id: req.body.employeeId }, select: { name: true, department: true } })
await auditLog(req, 'CREATE_DRAFT', 'TERMINATION_RECORD', result.id, {
employeeName: emp?.name || '',
department: emp?.department || '',
reason: req.body.reason || '',
type: req.body.type || 'TERMINATION',
terminationDate: req.body.terminationDate || '',
compensation: req.body.compensation || 0,
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'NOT_FOUND') {
@@ -210,7 +224,13 @@ router.put('/draft/:id', authMiddleware, async (req: AuthRequest, res, next) =>
router.post('/draft/:id/submit', authMiddleware, async (req: AuthRequest, res, next) => {
try {
const result = await submitForApproval(req.user!.orgId, req.params.id, req.user!.id)
await auditLog(req, 'SUBMIT_TERMINATION', 'TERMINATION_RECORD', req.params.id, {})
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true, type: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true } }) : null
await auditLog(req, 'SUBMIT_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
reason: termRecord?.reason || '',
type: termRecord?.type || '',
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'CONFLICT' || err?.code === 'NOT_FOUND') {
@@ -225,7 +245,13 @@ router.post('/draft/:id/approve', authMiddleware, async (req: AuthRequest, res,
try {
const { comment } = req.body
const result = await approveTermination(req.user!.orgId, req.params.id, req.user!.id, comment || '')
await auditLog(req, 'APPROVE_TERMINATION', 'TERMINATION_RECORD', req.params.id, { comment })
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true } }) : null
await auditLog(req, 'APPROVE_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
reason: termRecord?.reason || '',
comment: comment || '',
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'CONFLICT' || err?.code === 'NOT_FOUND') {
@@ -240,7 +266,13 @@ router.post('/draft/:id/reject', authMiddleware, async (req: AuthRequest, res, n
try {
const { comment } = req.body
const result = await rejectTermination(req.user!.orgId, req.params.id, req.user!.id, comment || '')
await auditLog(req, 'REJECT_TERMINATION', 'TERMINATION_RECORD', req.params.id, { comment })
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true } }) : null
await auditLog(req, 'REJECT_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
reason: termRecord?.reason || '',
comment: comment || '',
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'CONFLICT' || err?.code === 'NOT_FOUND') {
@@ -254,7 +286,16 @@ router.post('/draft/:id/reject', authMiddleware, async (req: AuthRequest, res, n
router.post('/draft/:id/execute', authMiddleware, async (req: AuthRequest, res, next) => {
try {
const result = await executeTermination(req.user!.orgId, req.params.id, req.user!.id)
await auditLog(req, 'EXECUTE_TERMINATION', 'TERMINATION_RECORD', req.params.id, {})
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true, type: true, terminationDate: true, compensation: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true, department: true } }) : null
await auditLog(req, 'EXECUTE_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
department: emp?.department || '',
reason: termRecord?.reason || '',
type: termRecord?.type || '',
terminationDate: termRecord?.terminationDate?.toISOString().slice(0, 10) || '',
compensation: termRecord?.compensation || 0,
})
await createEvidence({
orgId: req.user!.orgId,
category: 'TERMINATION',
@@ -276,7 +317,13 @@ router.post('/draft/:id/execute', authMiddleware, async (req: AuthRequest, res,
router.post('/draft/:id/cancel', authMiddleware, async (req: AuthRequest, res, next) => {
try {
const result = await cancelTermination(req.user!.orgId, req.params.id, req.user!.id)
await auditLog(req, 'CANCEL_TERMINATION', 'TERMINATION_RECORD', req.params.id, {})
const termRecord = await prisma.terminationRecord.findFirst({ where: { id: req.params.id }, select: { employeeId: true, reason: true, type: true } })
const emp = termRecord ? await prisma.employee.findFirst({ where: { id: termRecord.employeeId }, select: { name: true } }) : null
await auditLog(req, 'CANCEL_TERMINATION', 'TERMINATION_RECORD', req.params.id, {
employeeName: emp?.name || '',
reason: termRecord?.reason || '',
type: termRecord?.type || '',
})
res.json({ success: true, data: result })
} catch (err: any) {
if (err?.code === 'CONFLICT' || err?.code === 'NOT_FOUND') {