-
Notifications
You must be signed in to change notification settings - Fork 1
/
seeds.js
executable file
·80 lines (67 loc) · 2.04 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
var mongoose = require("mongoose");
var campaign = require("./models/campaign");
var Comment = require("./models/comment");
var data = require("./data.json");
var date = new Date();
var backDate = new Date();
backDate.setDate(date.getDate()-1);
donations =
[
// { text: "#Shutdown2018",
// amount: 6,
// author: {
// id: "59ecef01d17ab7684953ccb7",
// username: "Anton Maes"
// }
// //createdAt: date,
// //campaignID: campaign._id
// }
// ,
// { text: "#Shutdown2018",
// amount: 7,
// author: {
// id: "59ecef01d17ab7684953ccb7",
// username: "Anton Maes"
// },
// createdAt: backDate
// //campaignID: campaign._id
// }
];
function seedDB(){
// load data
// console.log("loading data");
// var rawData = fs.readFileSync("data.json");
// var data = json.parse(rawData);
// console.log("load complete");
//Remove all campaigns
campaign.remove({}, function(err){
if(err){
console.log(err);
}
console.log("removed campaigns!");
//add a few campaigns
data.forEach(function(seed){
campaign.create(seed, function(err, data){
if(err){
console.log(err)
} else {
console.log("added a campaign");
//create a comment
donations.forEach(function(commentData){
commentData.campaignID = campaign._id
Comment.create(commentData, function(err, comment){
if(err){
console.log(err);
} else {
campaign.comments.push(comment._id);
campaign.save();
console.log("Created new comment: ",comment.campaignID);
}
});
});
}});
});
});
//add a few comments
}
module.exports = seedDB;