-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
49 lines (44 loc) · 2.11 KB
/
seed.js
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
47
48
49
require("dotenv").config();
const mongoose = require('mongoose');
const Space = require('./models/space');
const winston = require('winston');
// Set up Winston logger
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'seed.log' })
]
});
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_CONNECTION)
.then(() => {
logger.info('Connected to MongoDB');
seedData();
})
.catch((error) => {
logger.error('Failed to connect to MongoDB:', error);
});
// Seed initial data
async function seedData() {
await Space.deleteMany(); // Clear existing data
const spaces = [
{ name: 'Meeting Room', location: 'Floor 1', description: 'A small meeting room for up to 6 people' },
{ name: 'Lounge Area', location: 'Ground Floor', description: 'A comfortable space for informal meetings or relaxation' },
{ name: 'Boardroom', location: 'Floor 2', description: 'A large boardroom for formal meetings with conference facilities' },
{ name: 'Quiet Zone', location: 'Floor 3', description: 'A peaceful area for focused work or reading' },
{ name: 'Collaboration Space', location: 'Floor 4', description: 'An open area designed for group work and brainstorming sessions' },
{ name: 'Training Room', location: 'Floor 1', description: 'A dedicated space for training sessions and workshops' },
{ name: 'Cafeteria', location: 'Ground Floor', description: 'A dining area offering various food options for employees' },
{ name: 'Tech Hub', location: 'Floor 5', description: 'An innovation hub equipped with the latest technology for experimentation' },
{ name: 'Wellness Center', location: 'Floor 3', description: 'A facility promoting employee well-being with fitness and relaxation amenities' },
{ name: 'Outdoor Terrace', location: 'Rooftop', description: 'A scenic outdoor space for events and gatherings' }
];
try {
await Space.insertMany(spaces);
logger.info('Data seeded successfully');
} catch (error) {
logger.error('Error seeding data:', error);
} finally {
mongoose.connection.close();
}
}