-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
79 lines (70 loc) · 2.2 KB
/
Copy pathseed.js
File metadata and controls
79 lines (70 loc) · 2.2 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require('dotenv').config();
const mongoose = require('mongoose');
const Event = require('./models/eventModel');
const Booth = require('./models/boothModel');
const User = require('./models/userModel');
const seedDB = async () => {
await mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true });
console.log('Connected to MongoDB for seeding...');
// Clear existing data
await Event.deleteMany({});
await Booth.deleteMany({});
console.log('Cleared existing events and booths...');
// Upsert testing users (admin and normal user)
await User.deleteMany({ userId: { $in: ['admin', 'admin2', 'testuser'] } });
const adminUser = new User({
userId: 'admin',
password: 'adminpass',
nickname: 'Admin',
email: 'admin@example.com',
role: 'admin'
});
const normalUser = new User({
userId: 'testuser',
password: 'password',
nickname: 'Test User',
email: 'testuser@example.com',
role: 'user'
});
await adminUser.save();
await normalUser.save();
console.log('Seeded test users: admin/adminpass and testuser/password');
// Create a dummy event
const event = new Event({
name: 'HK Food Carnival 2025',
date: new Date('2025-12-20'),
location: 'AsiaWorld-Expo',
description: 'The biggest food carnival in Hong Kong!',
coverImageUrl: 'https://images.unsplash.com/photo-1543353071-10c8ba85a904?q=80&w=1200&auto=format&fit=crop'
});
await event.save();
console.log('Created dummy event...');
// Create dummy booths
const booths = [];
for (let i = 1; i <= 25; i++) {
booths.push({
boothId: `A${i}`,
event: event._id,
floor: 1,
priceTier: i % 2 === 0 ? 'premium' : 'economy',
price: i % 2 === 0 ? 500 : 300,
});
}
for (let i = 1; i <= 15; i++) {
booths.push({
boothId: `B${i}`,
event: event._id,
floor: 2,
priceTier: i % 2 === 0 ? 'premium' : 'economy',
price: i % 2 === 0 ? 600 : 400,
});
}
await Booth.insertMany(booths);
console.log('Created 40 dummy booths...');
mongoose.connection.close();
console.log('Disconnected from MongoDB.');
};
seedDB().catch(err => {
console.error(err);
mongoose.connection.close();
});