53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import 'dotenv/config';
|
|
import bcrypt from 'bcryptjs';
|
|
import db from '../src/database/models/index.js';
|
|
import { ROLES } from '../src/common/config/constants.js';
|
|
|
|
const { User } = db;
|
|
|
|
async function seedUsers() {
|
|
console.log('🌱 Seeding users...');
|
|
try {
|
|
await db.sequelize.authenticate();
|
|
|
|
const hashedPassword = await bcrypt.hash('Admin@123', 10);
|
|
|
|
const usersToSeed = [
|
|
{
|
|
email: 'admin@royalenfield.com',
|
|
fullName: 'Super Admin',
|
|
password: hashedPassword,
|
|
roleCode: ROLES.SUPER_ADMIN,
|
|
status: 'active'
|
|
},
|
|
{
|
|
email: 'zm@royalenfield.com',
|
|
fullName: 'Zone Manager',
|
|
password: hashedPassword,
|
|
roleCode: ROLES.DD_ZM,
|
|
status: 'active'
|
|
},
|
|
{
|
|
email: 'dealer@example.com',
|
|
fullName: 'Amit Sharma',
|
|
password: hashedPassword,
|
|
roleCode: ROLES.DEALER,
|
|
status: 'active',
|
|
isExternal: true
|
|
}
|
|
];
|
|
|
|
for (const u of usersToSeed) {
|
|
await User.upsert(u);
|
|
}
|
|
|
|
console.log('✅ Users seeded successfully!');
|
|
process.exit(0);
|
|
} catch (error) {
|
|
console.error('❌ Seeding failed:', error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
seedUsers();
|