refactor(admin): 路由请求助手去重
finance / fund / cost-center 三个路由文件各自复制了 sessionOf / idOf / bodyOf, 语义相同写法不同。统一到 routes/admin/request-helpers.ts,路由文件只保留业务 差异(fund.ts 的 accountIdOf / expenseIdOf)。 无行为变更:typecheck、lint、773 个测试全部通过。
This commit is contained in:
@@ -60,7 +60,6 @@ import {
|
||||
syncAdminWorkOrderTemplateCostVersions,
|
||||
} from '../../services/cost-center/template-bootstrap-service.js'
|
||||
import { normalizeManualProducts } from '../../services/cost-center/manual-product-normalization-service.js'
|
||||
import type { AdminSession } from '../../services/admin/admin-auth-service.js'
|
||||
import {
|
||||
syncActualWorkOrderCostSnapshots,
|
||||
syncEstimatedOrderItemCostSnapshots,
|
||||
@@ -72,21 +71,10 @@ import {
|
||||
requireAdminRoles,
|
||||
requireAnyAdminPermission,
|
||||
} from './session.js'
|
||||
import { bodyOf, idOf, sessionOf } from './request-helpers.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
function sessionOf(req: Request): AdminSession {
|
||||
return req.adminSession as AdminSession
|
||||
}
|
||||
|
||||
function idOf(req: Request, key: string): number {
|
||||
return Number(req.params[key])
|
||||
}
|
||||
|
||||
function bodyOf(req: Request): JsonObject {
|
||||
return req.body && typeof req.body === 'object' ? (req.body as JsonObject) : {}
|
||||
}
|
||||
|
||||
router.use('/cost-center', requireAdminRoles(['admin', 'operator', 'finance', 'support']))
|
||||
|
||||
router.get(
|
||||
|
||||
Reference in New Issue
Block a user