const bcrypt = require('bcrypt'); const { pool } = require('./config/db'); const DASHBOARD_USERS = [ { email: 'ravi@stratawiz.com', password: 'qwerty', name: 'Ravi', role: 'admin' }, { email: 'projectmanager@crestindia.co.in', password: 'qwerty', name: 'Project Manager', role: 'admin' }, ]; /** * Ensure dashboard admins exist. Existing emails are left unchanged. */ async function seedUsers() { for (const user of DASHBOARD_USERS) { const email = user.email.trim().toLowerCase(); const [existing] = await pool.execute( 'SELECT id FROM users WHERE email = ? LIMIT 1', [email] ); if (existing.length) { console.log('Seed user already exists:', email); continue; } const passwordHash = await bcrypt.hash(user.password, 10); await pool.execute( `INSERT INTO users (name, email, password_hash, role, status) VALUES (?, ?, ?, ?, 'active')`, [user.name, email, passwordHash, user.role] ); console.log('Seeded dashboard user:', email); } } module.exports = { seedUsers };