彻底重构-3

This commit is contained in:
yml
2026-04-09 12:24:14 +08:00
parent 606ef875e2
commit 60054adcc4
37 changed files with 1324 additions and 3630 deletions
@@ -1,5 +1,6 @@
import { createAdminAuditLog, listAdminAuditLogs } from '../../repositories/admin-audit-log-repo.js'
import { nowIso } from '../../utils/time.js'
import { normalizeDateQuery, normalizePage, normalizePageSize, safeParseJson } from './admin-query-utils.js'
export async function writeAdminAuditLog(session, payload = {}) {
if (!session?.userId) {
@@ -46,38 +47,3 @@ export async function getAdminAuditLogs(query = {}) {
pagination: { page, pageSize, total },
}
}
function normalizePage(rawValue) {
const parsed = Number(rawValue)
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 1
}
function normalizePageSize(rawValue) {
const parsed = Number(rawValue)
if (!Number.isFinite(parsed) || parsed <= 0) {
return 20
}
return Math.min(100, Math.floor(parsed))
}
function normalizeDateQuery(rawValue, endOfDay = false) {
const normalized = String(rawValue || '').trim()
if (!normalized) {
return ''
}
if (/^\d{4}-\d{2}-\d{2}$/.test(normalized)) {
return endOfDay ? `${normalized}T23:59:59.999Z` : `${normalized}T00:00:00.000Z`
}
return normalized
}
function safeParseJson(value) {
try {
return typeof value === 'string' ? JSON.parse(value) : value || {}
} catch {
return {}
}
}