feat(user): 新增 update 命令 + create 补 enabledMark/sortCode/description
This commit is contained in:
1 parent
a37ba97576
commit
fc38b5407e
2 files changed
+51
-9
No files matched your search
@@ -15,6 +15,9 @@ interface CreateOpts {
|
||||
password: string
|
||||
organizeId?: string
|
||||
gender?: string
|
||||
enabledMark?: string
|
||||
sortCode?: string
|
||||
description?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
@@ -26,6 +29,9 @@ export function buildUserCreateCommand(): Command {
|
||||
.requiredOption('--password <p>', '明文密码 (后端会自动 md5 加密)')
|
||||
.option('--organizeId <id>', '所属组织 id (决策 7: 必须)')
|
||||
.option('--gender <g>', '性别: 1=男 2=女 3=未知', '1')
|
||||
.option('--enabledMark <m>', '状态: 0=禁用 1=启用 2=锁定', '1')
|
||||
.option('--sortCode <n>', '排序', '0')
|
||||
.option('--description <d>', '说明')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
@@ -36,10 +42,11 @@ export function buildUserCreateCommand(): Command {
|
||||
realName: opts.realName,
|
||||
password: md5Pwd,
|
||||
gender: opts.gender || '1',
|
||||
enabledMark: 1,
|
||||
sortCode: 0,
|
||||
enabledMark: opts.enabledMark || '1',
|
||||
sortCode: parseInt(opts.sortCode || '0', 10),
|
||||
}
|
||||
if (opts.organizeId) body.organizeId = opts.organizeId
|
||||
if (opts.description) body.description = opts.description
|
||||
const r = await c.postJson<{ id?: string }>('/permission/Users', body)
|
||||
if (r.code !== 200) {
|
||||
log.error(`user create 失败 (code=${r.code}): ${r.msg}`)
|
||||
|
||||
@@ -1,16 +1,51 @@
|
||||
/**
|
||||
* commands/user/update.ts — 占位, Task 4 实现
|
||||
* commands/user/update.ts — admin 编辑用户
|
||||
*
|
||||
* API: PUT /api/permission/Users/{id}
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
|
||||
interface UpdateOpts {
|
||||
id: string
|
||||
fields: string
|
||||
}
|
||||
|
||||
export function buildUserUpdateCommand(): Command {
|
||||
const cmd = new Command('update').description('TODO: implement in Task 4')
|
||||
cmd.action(async () => {
|
||||
log.warn('TODO: implement in Task 4')
|
||||
process.exit(1)
|
||||
const cmd = new Command('update')
|
||||
.description('编辑用户 (admin 操作, 部分字段更新)')
|
||||
.requiredOption('--id <uid>', '用户 id')
|
||||
.requiredOption('--fields <json>', '要更新的字段 JSON, 如 {"realName":"新名","email":"x@y"}')
|
||||
.action(async (opts: UpdateOpts) => {
|
||||
let fields: Record<string, unknown>
|
||||
try {
|
||||
fields = JSON.parse(opts.fields)
|
||||
} catch (e) {
|
||||
log.error(`JSON 解析失败: ${(e as Error).message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.putJson(`/permission/Users/${opts.id}`, fields)
|
||||
if (r.code !== 200) {
|
||||
log.error(`user update 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ 用户 id=${opts.id} 已更新: ${Object.keys(fields).join(', ')}`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '编辑用户 (admin 操作, PUT /Users/{id})',
|
||||
required: { '--id': '用户 id', '--fields': '字段 JSON (realName/email/mobilePhone/enabledMark/sortCode/...)' },
|
||||
example: 'dacli user update --id=1234567890 --fields=\'{"realName":"新名","email":"[email protected]"}\'',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/user/Form.vue',
|
||||
api: 'PUT /api/permission/Users/{id}',
|
||||
},
|
||||
notes: [
|
||||
'**决策 7**: organizeId 可通过 --fields 改 (用户改所属组织)',
|
||||
'**JSON**: --fields 必须合法 JSON, 失败会 exit(1)',
|
||||
],
|
||||
})
|
||||
installAiHelpHook(cmd, { purpose: 'TODO' })
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user