Assign admin role during admin seed

This commit is contained in:
2026-05-11 13:16:45 +07:00
parent 04fe3b4744
commit 23dd37424a

View File

@ -12,6 +12,33 @@ async function main() {
const email = 'admin@bizone.id'; const email = 'admin@bizone.id';
const password = 'ChangeMe123!'; const password = 'ChangeMe123!';
const passwordHash = await bcrypt.hash(password, 10); const passwordHash = await bcrypt.hash(password, 10);
const adminPermissions = [
{ id: 'campaigns', label: 'Manage Campaigns', icon: 'campaign', description: 'Broadcasts and outbound campaign controls.', values: { view: true, edit: true, delete: true, manage: true } },
{ id: 'analytics', label: 'View Analytics', icon: 'monitoring', description: 'KPI, trends, and performance dashboards.', values: { view: true, edit: null, delete: null, manage: true } },
{ id: 'settings', label: 'Edit Settings', icon: 'settings', description: 'Providers, secrets, and environment-facing settings.', values: { view: true, edit: true, delete: true, manage: true } },
{ id: 'billing', label: 'Billing & Invoices', icon: 'payments', description: 'Plan usage, invoices, and billing visibility.', values: { view: true, edit: null, delete: null, manage: true } },
];
const adminRole = await prisma.role.upsert({
where: { key: 'admin' },
update: {
name: 'Admin',
summary: 'Full access to all modules, security controls, system configuration, and account-wide actions.',
badge: 'Active',
tone: 'primary',
icon: 'shield_person',
permissionsJson: adminPermissions,
},
create: {
key: 'admin',
name: 'Admin',
summary: 'Full access to all modules, security controls, system configuration, and account-wide actions.',
badge: 'Active',
tone: 'primary',
icon: 'shield_person',
permissionsJson: adminPermissions,
},
});
const user = await prisma.user.upsert({ const user = await prisma.user.upsert({
where: { email }, where: { email },
@ -19,12 +46,14 @@ async function main() {
name: 'System Admin', name: 'System Admin',
passwordHash, passwordHash,
status: 'active', status: 'active',
roleId: adminRole.id,
}, },
create: { create: {
name: 'System Admin', name: 'System Admin',
email, email,
passwordHash, passwordHash,
status: 'active', status: 'active',
roleId: adminRole.id,
}, },
}); });