彻底重构-2

This commit is contained in:
yml
2026-04-09 10:17:50 +08:00
parent df2eb34478
commit 606ef875e2
4 changed files with 155 additions and 12 deletions
@@ -1,7 +1,7 @@
import { createAdminAuditLog, listAdminAuditLogs } from '../../repositories/admin-audit-log-repo.js'
import { nowIso } from '../../utils/time.js'
export function writeAdminAuditLog(session, payload = {}) {
export async function writeAdminAuditLog(session, payload = {}) {
if (!session?.userId) {
return null
}
@@ -18,10 +18,10 @@ export function writeAdminAuditLog(session, payload = {}) {
})
}
export function getAdminAuditLogs(query = {}) {
export async function getAdminAuditLogs(query = {}) {
const page = normalizePage(query.page)
const pageSize = normalizePageSize(query.pageSize)
const { items, total } = listAdminAuditLogs({
const { items, total } = await listAdminAuditLogs({
page,
pageSize,
actorUsername: String(query.actorUsername || '').trim(),
@@ -33,8 +33,8 @@ export function getAdminAuditLogs(query = {}) {
return {
items: items.map((item) => ({
logId: item.id,
actorUserId: item.actor_user_id,
logId: Number(item.id),
actorUserId: Number(item.actor_user_id || 0),
actorUsername: item.actor_username,
actorRole: item.actor_role,
action: item.action,
@@ -76,7 +76,7 @@ function normalizeDateQuery(rawValue, endOfDay = false) {
function safeParseJson(value) {
try {
return JSON.parse(String(value || '{}'))
return typeof value === 'string' ? JSON.parse(value) : value || {}
} catch {
return {}
}