import { PrismaClient } from '@prisma/client'; /** * Makes an existing dashboard user a superadmin, or an admin again with --revoke. There is no other way to become * the first superadmin: the dashboard only lets a superadmin hand out the role. * * pnpm --filter @kooltap/api run superadmin user@example.com [--revoke] */ async function main() { const [email, flag] = process.argv.slice(2); if (!email) { console.error('Usage: superadmin [--revoke]'); process.exit(1); } const role = flag === '--revoke' ? 'admin' : 'superadmin'; const prisma = new PrismaClient(); try { const user = await prisma.clientUser.findUnique({ where: { email } }); if (!user) { console.error(`No user with email ${email}`); process.exit(1); } await prisma.clientUser.update({ where: { id: user.id }, data: { role } }); console.log(`${email} is now ${role === 'superadmin' ? 'a superadmin' : 'an admin'}`); } finally { await prisma.$disconnect(); } } main();