50 lines
3.4 KiB
TypeScript
50 lines
3.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: 'rbm.ncr@royalenfield.com', fullName: 'Sanjay Dutt', password: hashedPassword, roleCode: ROLES.RBM, status: 'active' },
|
|
{ email: 'zm.ncr@royalenfield.com', fullName: 'Rajesh Khanna', password: hashedPassword, roleCode: ROLES.DD_ZM, status: 'active' },
|
|
{ email: 'legal@royalenfield.com', fullName: 'Legal Admin', password: hashedPassword, roleCode: ROLES.LEGAL_ADMIN, status: 'active' },
|
|
{ email: 'ddhead@royalenfield.com', fullName: 'Vikram Singh', password: hashedPassword, roleCode: ROLES.DD_HEAD, status: 'active' },
|
|
{ email: 'nbh@royalenfield.com', fullName: 'Alwyn John', password: hashedPassword, roleCode: ROLES.NBH, status: 'active' },
|
|
{ email: 'ddlead@royalenfield.com', fullName: 'Meera Iyer', password: hashedPassword, roleCode: ROLES.DD_LEAD, status: 'active' },
|
|
{ email: 'finance@royalenfield.com', fullName: 'Rahul Verma', password: hashedPassword, roleCode: ROLES.FINANCE, status: 'active' },
|
|
{ email: 'dealer@royalenfield.com', fullName: 'Amit Sharma', password: hashedPassword, roleCode: ROLES.DEALER, status: 'active', isExternal: true },
|
|
{ email: 'admin@royalenfield.com', fullName: 'Laxman H', password: hashedPassword, roleCode: ROLES.DD_LEAD, status: 'active' },
|
|
{ email: 'yashwin@gmail.com', fullName: 'Yashwin', password: hashedPassword, roleCode: ROLES.ZBH, status: 'active' },
|
|
{ email: 'kenil@gmail.com', fullName: 'Kenil', password: hashedPassword, roleCode: ROLES.DD_LEAD, status: 'active' },
|
|
{ email: 'lince@gmail.com', fullName: 'Lince', password: hashedPassword, roleCode: ROLES.DD_ADMIN, status: 'active' },
|
|
{ email: 'fdd@royalenfield.com', fullName: 'FDD Partner', password: hashedPassword, roleCode: ROLES.FDD, status: 'active' },
|
|
{ email: 'architecture@royalenfield.com', fullName: 'RE Architect', password: hashedPassword, roleCode: ROLES.ARCHITECTURE, status: 'active' },
|
|
{ email: 'cco@royalenfield.com', fullName: 'Ashok Singh (CCO)', password: hashedPassword, roleCode: ROLES.CCO, status: 'active' },
|
|
{ email: 'ceo@royalenfield.com', fullName: 'Siddhartha Lal (CEO)', password: hashedPassword, roleCode: ROLES.CEO, status: 'active' },
|
|
{ email: 'spares@royalenfield.com', fullName: 'Spares Clearance Mgr', password: hashedPassword, roleCode: ROLES.SPARES_MANAGER, status: 'active' },
|
|
{ email: 'service@royalenfield.com', fullName: 'Service Clearance Mgr', password: hashedPassword, roleCode: ROLES.SERVICE_MANAGER, status: 'active' },
|
|
{ email: 'accounts@royalenfield.com', fullName: 'Accounts Clearance Mgr', password: hashedPassword, roleCode: ROLES.ACCOUNTS_MANAGER, status: 'active' }
|
|
];
|
|
|
|
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();
|