feat(user): 新增 socials-unbind 命令 (admin 解绑社交账号)
This commit is contained in:
1 parent
86780c6ff0
commit
c275391ced
1 file changed
+70
-7
@@ -1,16 +1,79 @@
|
||||
/**
|
||||
* commands/user/socials-unbind.ts — 占位, Task 12 实现
|
||||
* commands/user/socials-unbind.ts — admin 解绑社交账号
|
||||
*
|
||||
* API:
|
||||
* 1) GET /api/permission/socials?userId={uid} 查绑定列表
|
||||
* 2) DELETE /api/permission/socials/{userId}/{socialsId} 解绑
|
||||
*
|
||||
* web 端触发: SocialsBind.vue, handleDel(item.entity.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 SocialsItem {
|
||||
name?: string
|
||||
description?: string
|
||||
entity?: { id?: string }
|
||||
}
|
||||
|
||||
interface SocialsUnbindOpts {
|
||||
userId: string
|
||||
socialsId?: string
|
||||
list?: boolean
|
||||
}
|
||||
|
||||
export function buildUserSocialsUnbindCommand(): Command {
|
||||
const cmd = new Command('socials-unbind').description('TODO: implement in Task 12')
|
||||
cmd.action(async () => {
|
||||
log.warn('TODO: implement in Task 12')
|
||||
process.exit(1)
|
||||
const cmd = new Command('socials-unbind')
|
||||
.description('解绑社交账号 (admin 操作)')
|
||||
.requiredOption('--userId <uid>', '用户 id')
|
||||
.option('--socialsId <sid>', '社交账号 entity.id (web 端 entity.id)')
|
||||
.option('--list', '列出该用户的所有社交账号绑定, 不解绑', false)
|
||||
.action(async (opts: SocialsUnbindOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// Step 1: 查绑定列表
|
||||
const listRes = await c.get<SocialsItem[]>('/permission/socials', {
|
||||
userId: opts.userId,
|
||||
})
|
||||
if (listRes.code !== 200) {
|
||||
log.error(`socials 列表失败 (code=${listRes.code}): ${listRes.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const list = listRes.data || []
|
||||
if (opts.list || !opts.socialsId) {
|
||||
log.info(`用户 id=${opts.userId} 共 ${list.length} 个社交账号绑定`)
|
||||
for (const it of list) {
|
||||
console.log(` ${it.entity?.id || '(无 entity)'} ${it.name} (${it.description || ''})`)
|
||||
}
|
||||
if (!opts.socialsId) {
|
||||
log.info('用 --socialsId=<id> 解绑指定账号')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Step 2: 解绑
|
||||
const r = await c.del(`/permission/socials/${opts.userId}/${opts.socialsId}`)
|
||||
if (r.code !== 200) {
|
||||
log.error(`socials-unbind 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ 用户 id=${opts.userId} 社交账号 socialsId=${opts.socialsId} 已解绑`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '解绑社交账号 (admin 操作)',
|
||||
required: { '--userId': '用户 id' },
|
||||
optional: { '--socialsId': '社交账号 entity.id (不传只列出)', '--list': '只列出不解绑' },
|
||||
example: 'dacli user socials-unbind --userId=1234567890 --socialsId=abc123',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/user/SocialsBind.vue',
|
||||
api: 'DELETE /api/permission/socials/{userId}/{socialsId}',
|
||||
},
|
||||
notes: [
|
||||
'**先列后绑**: 不传 --socialsId 时只列, 传后才解绑 (二段式防误操作)',
|
||||
'**实体 id**: 用 web 端 SocialsBind.vue 看到的 entity.id, 不是社交平台 userId',
|
||||
],
|
||||
})
|
||||
installAiHelpHook(cmd, { purpose: 'TODO' })
|
||||
return cmd
|
||||
}
|
||||
Reference in new issue
Block a user