ts类型检查

This commit is contained in:
yml
2026-05-04 09:43:38 +08:00
parent a914b7b828
commit 66261e56d1
23 changed files with 223 additions and 76 deletions
+52 -25
View File
@@ -10,6 +10,18 @@ import {
} from '../../services/admin/admin-auth-service.js'
import { createJsonHandler, requireAdminRoles } from './shared.js'
/**
* @typedef {{
* user: {
* userId: number
* username: string
* role: string
* status?: string
* inventoryGroupCodes?: string[]
* }
* }} AdminUserMutationResult
*/
const router = Router()
router.use('/users', requireAdminRoles(['admin']))
@@ -29,16 +41,19 @@ router.post('/users', createJsonHandler(
successMessage: '后台用户已创建',
errorMessage: '创建后台用户失败',
scope: '[admin/users:create]',
audit: (_req, data) => ({
audit: (_req, data) => {
const result = /** @type {AdminUserMutationResult} */ (data)
return {
action: 'admin_user_created',
targetType: 'admin_user',
targetId: String(data.user.userId),
targetId: String(result.user.userId),
data: {
username: data.user.username,
role: data.user.role,
status: data.user.status,
username: result.user.username,
role: result.user.role,
status: result.user.status,
},
}),
}
},
},
))
@@ -48,15 +63,18 @@ router.post('/users/:userId/role', createJsonHandler(
successMessage: '用户角色已更新',
errorMessage: '更新用户角色失败',
scope: '[admin/users/:userId/role]',
audit: (_req, data) => ({
audit: (_req, data) => {
const result = /** @type {AdminUserMutationResult} */ (data)
return {
action: 'admin_user_role_updated',
targetType: 'admin_user',
targetId: String(data.user.userId),
targetId: String(result.user.userId),
data: {
username: data.user.username,
role: data.user.role,
username: result.user.username,
role: result.user.role,
},
}),
}
},
},
))
@@ -66,15 +84,18 @@ router.post('/users/:userId/status', createJsonHandler(
successMessage: '用户状态已更新',
errorMessage: '更新用户状态失败',
scope: '[admin/users/:userId/status]',
audit: (_req, data) => ({
audit: (_req, data) => {
const result = /** @type {AdminUserMutationResult} */ (data)
return {
action: 'admin_user_status_updated',
targetType: 'admin_user',
targetId: String(data.user.userId),
targetId: String(result.user.userId),
data: {
username: data.user.username,
status: data.user.status,
username: result.user.username,
status: result.user.status,
},
}),
}
},
},
))
@@ -84,15 +105,18 @@ router.post('/users/:userId/inventory-groups', createJsonHandler(
successMessage: '用户库存组已更新',
errorMessage: '更新用户库存组失败',
scope: '[admin/users/:userId/inventory-groups]',
audit: (_req, data) => ({
audit: (_req, data) => {
const result = /** @type {AdminUserMutationResult} */ (data)
return {
action: 'admin_user_inventory_groups_updated',
targetType: 'admin_user',
targetId: String(data.user.userId),
targetId: String(result.user.userId),
data: {
username: data.user.username,
inventoryGroupCodes: data.user.inventoryGroupCodes,
username: result.user.username,
inventoryGroupCodes: result.user.inventoryGroupCodes,
},
}),
}
},
},
))
@@ -102,14 +126,17 @@ router.post('/users/:userId/reset-password', createJsonHandler(
successMessage: '用户密码已重置',
errorMessage: '重置用户密码失败',
scope: '[admin/users/:userId/reset-password]',
audit: (_req, data) => ({
audit: (_req, data) => {
const result = /** @type {AdminUserMutationResult} */ (data)
return {
action: 'admin_user_password_reset',
targetType: 'admin_user',
targetId: String(data.user.userId),
targetId: String(result.user.userId),
data: {
username: data.user.username,
username: result.user.username,
},
}),
}
},
},
))