flnxi-Wu/scripts/tools/activate-admin.js
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

82 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient({
datasources: {
db: {
url: process.env.DATABASE_URL
}
}
});
async function main() {
try {
const email = '549727955@qq.com';
const username = '神秘男子';
console.log('正在查找用户...');
console.log(`邮箱: ${email}`);
console.log(`用户名: ${username}`);
console.log('');
// 查找用户
let user = await prisma.user.findFirst({
where: {
OR: [
{ email: email },
{ username: username }
]
}
});
if (!user) {
console.log('❌ 未找到用户,请确认邮箱或用户名是否正确');
process.exit(1);
}
console.log('找到用户:');
console.log(` ID: ${user.id}`);
console.log(` 邮箱: ${user.email}`);
console.log(` 用户名: ${user.username}`);
console.log(` 当前角色: ${user.role}`);
console.log(` 当前状态: ${user.isActive ? '已激活' : '未激活'}`);
console.log(` 当前部门: ${user.department || '未设置'}`);
console.log('');
// 更新用户
console.log('正在更新用户...');
user = await prisma.user.update({
where: {
id: user.id
},
data: {
isActive: true,
role: 'ADMIN',
department: '111'
}
});
console.log('✅ 用户更新成功!');
console.log('');
console.log('更新后的信息:');
console.log(` 邮箱: ${user.email}`);
console.log(` 用户名: ${user.username}`);
console.log(` 角色: ${user.role}`);
console.log(` 状态: ${user.isActive ? '已激活' : '未激活'}`);
console.log(` 部门: ${user.department}`);
console.log('');
console.log('✅ 账户已激活并设置为管理员,部门已设置为111');
} catch (error) {
console.error('❌ 操作失败:', error.message);
if (error.meta) {
console.error('详细信息:', error.meta);
}
process.exit(1);
} finally {
await prisma.$disconnect();
}
}
main();