后端迁移后台管理基础服务
This commit is contained in:
+4
-2
@@ -2,7 +2,9 @@ import { createAdminAuditLog, listAdminAuditLogs } from '../../repositories/admi
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { normalizeDateQuery, normalizePage, normalizePageSize, safeParseJson } from './admin-query-utils.js'
|
||||
|
||||
export async function writeAdminAuditLog(session, payload = {}) {
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function writeAdminAuditLog(session: JsonObject | null | undefined, payload: JsonObject = {}) {
|
||||
if (!session?.userId) {
|
||||
return null
|
||||
}
|
||||
@@ -19,7 +21,7 @@ export async function writeAdminAuditLog(session, payload = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getAdminAuditLogs(query = {}) {
|
||||
export async function getAdminAuditLogs(query: JsonObject = {}) {
|
||||
const page = normalizePage(query.page)
|
||||
const pageSize = normalizePageSize(query.pageSize)
|
||||
const { items, total } = await listAdminAuditLogs({
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
// @ts-check
|
||||
|
||||
import { query } from '../../db/client.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function getAdminDashboardSummary() {
|
||||
const todayPrefix = nowIso().slice(0, 10)
|
||||
const result = await query(
|
||||
@@ -39,7 +39,7 @@ export async function getAdminDashboardSummary() {
|
||||
`,
|
||||
[todayPrefix],
|
||||
)
|
||||
const summary = result.rows[0] || {}
|
||||
const summary: JsonObject = result.rows[0] || {}
|
||||
|
||||
return {
|
||||
todayOrders: Number(summary?.today_orders || 0),
|
||||
+5
-6
@@ -1,12 +1,11 @@
|
||||
// @ts-check
|
||||
|
||||
import { listMessageDeliveries } from '../../repositories/message-delivery-repo.js'
|
||||
import { normalizeDateQuery, normalizePage, normalizePageSize, safeParseJson } from './admin-query-utils.js'
|
||||
|
||||
/** @typedef {import('../../types/admin-read-inputs.js').AdminMessageDeliveryListQueryInput} AdminMessageDeliveryListQueryInput */
|
||||
import type { AdminMessageDeliveryListQueryInput } from '../../types/admin-read-inputs.js'
|
||||
|
||||
/** @param {AdminMessageDeliveryListQueryInput} [query] */
|
||||
export async function getAdminMessageDeliveries(query = /** @type {AdminMessageDeliveryListQueryInput} */ ({})) {
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export async function getAdminMessageDeliveries(query: AdminMessageDeliveryListQueryInput = {}) {
|
||||
const page = normalizePage(query.page)
|
||||
const pageSize = normalizePageSize(query.pageSize)
|
||||
const { items, total } = await listMessageDeliveries({
|
||||
@@ -28,7 +27,7 @@ export async function getAdminMessageDeliveries(query = /** @type {AdminMessageD
|
||||
}
|
||||
}
|
||||
|
||||
function mapAdminMessageDeliveryListItem(item) {
|
||||
function mapAdminMessageDeliveryListItem(item: JsonObject) {
|
||||
return {
|
||||
deliveryId: Number(item.id),
|
||||
provider: String(item.provider || '').trim(),
|
||||
+6
-4
@@ -1,9 +1,11 @@
|
||||
export function normalizePage(rawValue) {
|
||||
type JsonObject = Record<string, any>
|
||||
|
||||
export function normalizePage(rawValue: unknown) {
|
||||
const parsed = Number(rawValue)
|
||||
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 1
|
||||
}
|
||||
|
||||
export function normalizePageSize(rawValue) {
|
||||
export function normalizePageSize(rawValue: unknown) {
|
||||
const parsed = Number(rawValue)
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return 20
|
||||
@@ -11,7 +13,7 @@ export function normalizePageSize(rawValue) {
|
||||
return Math.min(100, Math.floor(parsed))
|
||||
}
|
||||
|
||||
export function normalizeDateQuery(rawValue, endOfDay = false) {
|
||||
export function normalizeDateQuery(rawValue: unknown, endOfDay = false) {
|
||||
const normalized = String(rawValue || '').trim()
|
||||
|
||||
if (!normalized) {
|
||||
@@ -25,7 +27,7 @@ export function normalizeDateQuery(rawValue, endOfDay = false) {
|
||||
return normalized
|
||||
}
|
||||
|
||||
export function safeParseJson(rawText) {
|
||||
export function safeParseJson(rawText: unknown): JsonObject {
|
||||
if (rawText && typeof rawText === 'object') {
|
||||
return rawText
|
||||
}
|
||||
@@ -703,6 +703,18 @@
|
||||
- `npm run typecheck`
|
||||
- `npm run build`
|
||||
- `npm test` 共 139 个用例通过
|
||||
174. 后台 Admin 查询 / 审计 / 仪表盘 / 消息投递 / 写入口迁移到 `.ts`:
|
||||
- `src/services/admin/admin-query-utils.ts`
|
||||
- `src/services/admin/admin-audit-service.ts`
|
||||
- `src/services/admin/admin-dashboard-service.ts`
|
||||
- `src/services/admin/admin-message-delivery-service.ts`
|
||||
- `src/services/admin/admin-write-service.ts`
|
||||
175. Admin 分页与日期查询归一化、审计日志写入 / 查询、仪表盘汇总、消息投递列表、后台写操作聚合入口已进入 TS 编译链路;query、session、payload、映射 row 补齐动态对象类型
|
||||
176. Docker 内验证通过:
|
||||
- `src/services/admin/*.test.js` 共 8 个用例通过
|
||||
- `npm run typecheck`
|
||||
- `npm run build`
|
||||
- `npm test` 共 139 个用例通过
|
||||
|
||||
## 下一步建议
|
||||
|
||||
|
||||
Reference in New Issue
Block a user