39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import 'dotenv/config';
|
|
import db from '../src/database/models/index.js';
|
|
import { ROLES } from '../src/common/config/constants.js';
|
|
|
|
const { Role } = db;
|
|
|
|
const rolesToSeed = [
|
|
{ roleCode: ROLES.SUPER_ADMIN, roleName: 'Super Admin', category: 'ADMIN', description: 'Full system access' },
|
|
{ roleCode: ROLES.DD_ADMIN, roleName: 'DD Admin', category: 'ADMIN', description: 'Dealer Development Admin' },
|
|
{ roleCode: ROLES.DD_HEAD, roleName: 'DD Head', category: 'LEVEL_3', description: 'DD Head' },
|
|
{ roleCode: ROLES.DD_LEAD, roleName: 'DD Lead', category: 'LEVEL_2', description: 'DD Lead' },
|
|
{ roleCode: ROLES.DD_ZM, roleName: 'DD-ZM', category: 'LEVEL_1', description: 'DD Zone Manager' },
|
|
{ roleCode: ROLES.ZBH, roleName: 'ZBH', category: 'ZONAL', description: 'Zonal Business Head' },
|
|
{ roleCode: ROLES.RBM, roleName: 'RBM', category: 'REGIONAL', description: 'Regional Business Manager' },
|
|
{ roleCode: ROLES.FINANCE, roleName: 'Finance', category: 'DEPARTMENT', description: 'Finance Department' },
|
|
{ roleCode: ROLES.LEGAL_ADMIN, roleName: 'Legal Admin', category: 'DEPARTMENT', description: 'Legal Department' },
|
|
{ roleCode: ROLES.NBH, roleName: 'NBH', category: 'NATIONAL', description: 'National Business Head' },
|
|
{ roleCode: ROLES.DEALER, roleName: 'Dealer', category: 'EXTERNAL', description: 'Dealer Principal' }
|
|
];
|
|
|
|
async function seedRoles() {
|
|
console.log('🌱 Seeding roles...');
|
|
try {
|
|
await db.sequelize.authenticate();
|
|
|
|
for (const r of rolesToSeed) {
|
|
await Role.upsert(r);
|
|
}
|
|
|
|
console.log('✅ Roles seeded successfully!');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Seeding failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
seedRoles();
|