-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseeds.js
124 lines (117 loc) · 4.15 KB
/
seeds.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var Student = require("./models/studentModel");
var Post = require("./models/postModel");
var studentData = [];
var postData = [];
function createStudents() {
var passout_year = [2021, 2022, 2023, 2024];
var branch = ['CSE', 'ISE', 'Mech', 'Civil'];
var branch_prefix = ['CS', 'IS', 'MC', 'CV'];
var gender = ['male', 'female'];
var contact_number = '9999999999'
var email_id = '[email protected]';
var resume_url = 'https://fake.jsonresume.org/'
for (let branch_count = 0; branch_count < 4; branch_count++) {
for (let passout_year_count = 0; passout_year_count < 4; passout_year_count++) {
var cgpa = 7.0
var passout_year_prefix = (passout_year[passout_year_count] - 2004).toString()
for (let cgpa_count = 1; cgpa <= 10.0; cgpa_count++, cgpa = cgpa + 0.1) {
var data = {
usn: '1MS' + passout_year_prefix + branch_prefix[branch_count] + cgpa_count.toString(),
name: 'student' + cgpa_count.toString() + '(' + passout_year_prefix + ')',
passout_year: passout_year[passout_year_count],
branch: branch[branch_count],
gender: gender[cgpa_count % 2],
contact_number: contact_number,
email_id: email_id,
cgpa: cgpa,
resume_url: resume_url
};
studentData.push(data);
}
}
}
}
function createPosts() {
var job_description = "This is a dummy job"
var job_type = ['Permanent', 'Internship'];
var company_name = "Dummy Company";
var location = 'Bengaluru';
var allowed_branches = ['CSE', 'ISE', 'Mech', 'Civil'];
var deadline = Date.now();
var Salary = '2398472394'
for (let branch_count = 0; branch_count < 4; branch_count++) {
for (let min_cgpa = 7; min_cgpa < 10; min_cgpa++) {
for (let count = 1; count < 11; count++) {
let data = {
job_title: "Job_" + allowed_branches[branch_count].toString() + count.toString(),
job_description: job_description,
job_type: job_type[count % 2],
company_name: company_name,
min_cgpa: min_cgpa,
location: location,
allowed_branches: allowed_branches[branch_count],
Salary: Salary,
deadline: deadline
}
postData.push(data);
}
}
}
}
function seedDB() {
Student.deleteMany({}, function (err) {
if (err) {
return res.status(500).json({
message: 'Error when deleting post.',
error: err
});
}
});
console.log("Deleted Students");
createStudents();
Student.insertMany(studentData, function (err) {
if (err) {
console.log(err);
}
else console.log("Students added to db")
})
// studentData.forEach(function (seed) {
// Student.create(seed, function (err, student) {
// if (err) {
// return res.status(500).json({
// message: 'Error when deleting post.',
// error: err
// });
// }
// });
// });
console.log('Students created');
Post.deleteMany({}, function (err) {
if (err) {
return res.status(500).json({
message: 'Error when deleting post.',
error: err
});
}
});
console.log("Posts deleted");
createPosts();
Post.insertMany(postData, function (err) {
if (err) {
console.log(err);
}
else console.log("Posts added to db")
})
// postData.forEach(function (seed) {
// Student.create(seed, function (err) {
// if (err) {
// return res.status(500).json({
// message: 'Error when deleting post.',
// error: err
// });
// }
// });
// });
console.log("Posts created");
}
module.exports = seedDB;