-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
60 lines (51 loc) · 1.36 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
50
51
52
53
54
55
56
57
58
59
60
var Promise = require('bluebird');
var mongoose = require('mongoose');
var models = require('./models');
var Library = Promise.promisifyAll(models.Library);
var Api = Promise.promisifyAll(models.Api);
var jsData = require('./scrapers/scrapeJavascripting');
var pwData = require('./scrapers/scrapeProgWeb');
mongoose.connection.on('open', function(){
console.log('I am open');
mongoose.connection.db.dropDatabase(function(){
console.log('Dropped old data, now inserting data');
Promise.all([populateJS(), populatePW()]).then(function(results){
if(results){
console.log("Finished inserting data");
console.log("Control-C to quit");
}
}).catch(function(e){
throw new Error(e);
});
});
});
function populateJS(){
jsData.then(function(jsArr){
console.log('JS Data is in.');
jsArr.map(function(el){
return Library.create(el);
});
Promise.all(jsArr).then(function(el){
console.log('Library DB is all populated.');
return "done";
}).catch(function(el){
throw new Error(e);
});
}).catch(function(e){
throw new Error(e);
});
}
function populatePW(){
pwData.then(function(pwArr){
console.log('PW Data is in.');
pwArr.map(function(el){
return Api.create(el);
});
Promise.all(pwArr).then(function(el){
console.log('API DB is all populated.');
return "done";
}).catch(function(e){
throw new Error(e);
});
});
}