67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { PrismaClient } from './generated/prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
try {
|
|
// Create the admin role if it doesn't exist
|
|
const adminRole = await prisma.role.upsert({
|
|
where: { moniker: 'admin' },
|
|
update: {},
|
|
create: {
|
|
title: 'Administrator',
|
|
moniker: 'admin',
|
|
permissions: JSON.stringify({
|
|
// Full permissions for admin
|
|
'*': true,
|
|
}),
|
|
},
|
|
});
|
|
|
|
console.log('✓ Admin role created/verified:', adminRole);
|
|
|
|
// Find the user with jackson.roberts@totaltech.net
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: 'jackson.roberts@totaltech.net' },
|
|
include: { roles: true },
|
|
});
|
|
|
|
if (!user) {
|
|
console.error(
|
|
'✗ User jackson.roberts@totaltech.net not found. Please ensure the user exists.',
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('✓ User found:', user.email);
|
|
|
|
// Check if user already has admin role
|
|
const hasAdminRole = user.roles.some((r) => r.moniker === 'admin');
|
|
|
|
if (hasAdminRole) {
|
|
console.log('✓ User already has admin role');
|
|
} else {
|
|
// Assign admin role to user
|
|
const updatedUser = await prisma.user.update({
|
|
where: { id: user.id },
|
|
data: {
|
|
roles: {
|
|
connect: { id: adminRole.id },
|
|
},
|
|
},
|
|
include: { roles: true },
|
|
});
|
|
|
|
console.log('✓ Admin role assigned to jackson.roberts@totaltech.net');
|
|
console.log('✓ User roles:', updatedUser.roles.map((r) => r.moniker));
|
|
}
|
|
} catch (error) {
|
|
console.error('✗ Error:', error);
|
|
process.exit(1);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
main();
|