-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
137 lines (128 loc) · 3.07 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
var db = require('./models/index');
var faker = require('faker');
var bodyParser = require('body-parser');
var count = process.argv[5] || 5;
var usersList = [
{
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
password: faker.internet.password(),
image: faker.image.image()
},
{
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
password: faker.internet.password(),
image: faker.image.image()
},
{
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
password: faker.internet.password(),
image: faker.image.image()
},
{
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
password: faker.internet.password(),
image: faker.image.image()
}
];
var locations = [
{
city: 'San Francisco',
image: faker.image.image()
},
{
city: 'Sydney',
image: faker.image.image()
},
{
city: 'London',
image: faker.image.image()
},
{
city: 'Seattle',
image: faker.image.image()
}
]
var posts = [
{
title: 'Interesting',
description: 'Test description',
location: 'San Francisco'
},
{
title:'testing2',
description: 'something cool',
location: 'Sydney'
},
{
title: 'Second post for SF',
description: 'Test description 2',
location: 'San Francisco'
}
]
db.Post.remove({}, function(err){
if(err){
console.log(err, "something's wrong with removing posts")
}
console.log("removed all posts");
db.Post.create(posts, function(err, success){
if(err){
return console.log(err);
};
console.log("CREATED POSTS", success);
});
});
db.User.remove({}, function(err){
console.log("removed all users!")
db.User.create(usersList, function(err, success){
if(err){
console.log("there was an error!", err)
return;
}
console.log("created a user!", success)
})
console.log("Seed complete");
});
db.Location.remove({}, function(err){
console.log('removed all locations');
locations.forEach(function(locationData){
console.log('trying to find one city', locationData.city);
var local = new db.Location({
city: locationData.city,
image: locationData.image
});
db.Post.find({location: locationData.city}, function(err, foundPost){
console.log('logging what foundPost is after line 104', foundPost);
if(err){
console.log('Error finding loation', err);
}
local.posts = foundPost;
console.log('local.post on 110', local.posts);
local.save(function(err, savedLocal){
if(err){
return console.log(err);
}
console.log('savedLocal', savedLocal);
})
// local.posts.push(foundPost);
// local.save(function(err, savedLocal){
// if (err){
// console.log('save did not work', err)
// }
// });
console.log('saved local', local)
});
});
});
// db.Location.create(locations, function(err, success){
// if(err){
// console.log(err)
// return;
// }
// console.log('location created', success);
// });
// console.log('location seed compeleted');
// })