-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
46 lines (40 loc) · 1.57 KB
/
Copy pathseed.js
File metadata and controls
46 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'dotenv/config';
import mongoose from 'mongoose';
import Specialization from './Models/specialization.model.js';
import User from './Models/user.model.js';
const seedDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/medical_clinic_db');
console.log('Connected to MongoDB');
// Create specialization if it doesn't exist
let spec = await Specialization.findOne({ name: 'Cardiology' });
if (!spec) {
spec = await Specialization.create({ name: 'Cardiology', description: 'Heart specialist' });
console.log('Created specialization:', spec._id);
} else {
console.log('Specialization exists:', spec._id);
}
// Create admin user if doesn't exist
let admin = await User.findOne({ email: 'admin@test.com' });
if (!admin) {
admin = await User.create({
userName: 'Admin',
email: 'admin@test.com',
password: 'Admin1234',
role: 'Admin',
status: 'Active'
});
console.log('Created admin user:', admin._id);
} else {
console.log('Admin exists:', admin._id);
}
console.log('\nSeed data ready!');
console.log('Specialization ID:', spec._id.toString());
console.log('Admin email: admin@test.com / password: Admin1234');
await mongoose.disconnect();
} catch (error) {
console.error('Seed error:', error.message);
process.exit(1);
}
};
seedDB();