import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function main() { const user = await prisma.user.findFirst({ where: { status: 'ACTIVE', OR: [{ displayName: { contains: '孙春庆' } }, { employee: { name: { contains: '孙春庆' } } }], }, include: { roles: true }, }); if (!user) throw new Error('没有找到孙春庆'); const role = (await prisma.role.findFirst({ where: { code: 'bid_screener' } })) || (await prisma.role.create({ data: { name: '项目筛选发起', code: 'bid_screener', dataScope: 'SELF' }, })); const perms = await prisma.permission.findMany({ where: { code: { in: ['office', 'office:overview', 'bid', 'bid:screening'] } }, }); await prisma.rolePermission.createMany({ data: perms.map((p) => ({ roleId: role.id, permissionId: p.id })), skipDuplicates: true, }); await prisma.userRole.createMany({ data: [{ userId: user.id, roleId: role.id }], skipDuplicates: true, }); console.log(`granted bid screening to ${user.displayName} (${user.username})`); } main() .then(async () => prisma.$disconnect()) .catch(async (e) => { console.error(e); await prisma.$disconnect(); process.exit(1); });