forked from ajstocchetti/nomz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
130 lines (106 loc) · 4.13 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
/*
This seed file is only a placeholder. It should be expanded and altered
to fit the development of your application.
It uses the same file the server uses to establish
the database connection:
--- server/db/index.js
The name of the database used is set in your environment files:
--- server/env/*
This seed file has a safety check to see if you already have users
in the database. If you are developing multiple applications with the
fsg scaffolding, keep in mind that fsg always uses the same database
name in the environment files.
*/
require('dotenv').load();
var mongoose = require('mongoose');
var Promise = require('bluebird');
var chalk = require('chalk');
var connectToDb = require('./server/db');
var User = Promise.promisifyAll(mongoose.model('User'));
var seedUsers = function () {
var users = [
{
_id: '1',
email: '[email protected]',
password: 'ian',
username: 'ian',
following: [2, 3],
userImage: 'https://media.licdn.com/media/AAEAAQAAAAAAAAI3AAAAJDYxODhlZTM3LTYxMWQtNDNlOS05MzUxLTg2Y2JiYTQxYWYyZA.jpg',
posts: [
{
imageUrl: 'http://www.nutritionistinthekitch.com/wp-content/uploads/2012/11/IMGP5330.jpg',
date: new Date(2014, 1, 2),
caption: 'here is a caption for ians post',
menuItem: '119285'
},
{
imageUrl: 'http://s3-media1.fl.yelpcdn.com/bphoto/6veXte2d1fI2QxFOpwLN8Q/168s.jpg',
date: new Date(2012, 2, 3),
caption: 'here is a caption for ians second post',
menuItem: '119290'
}
],
},
{
_id: '2',
email: '[email protected]',
password: 'andy',
username: 'andy',
following: [1],
userImage: 'https://media.licdn.com/mpr/mpr/shrinknp_400_400/AAEAAQAAAAAAAANPAAAAJDk4NzI1NDAzLWQ0N2MtNDA4YS1hMGEwLWMwOThhMWY2NTNjZA.jpg',
posts: [
{
imageUrl: 'http://si.wsj.net/public/resources/images/NY-BY632_LUNCHB_P_20121016170840.jpg',
date: new Date(2013, 1, 2),
caption: 'here is a caption for andys post',
menuItem: '119281'
},
{
imageUrl: 'http://si.wsj.net/public/resources/images/NY-BY632_LUNCHB_P_20121016170840.jpg',
date: new Date(2014, 4, 2),
caption: 'here is a caption for andys second post',
menuItem: '24968814'
},
],
},
{
_id: '3',
email: '[email protected]',
password: 'peter',
username: 'peter',
userImage: 'https://media.licdn.com/mpr/mpr/shrinknp_400_400/AAEAAQAAAAAAAASTAAAAJDk1NTAwNGQ3LTQ2YzYtNGJjMy1hNzA0LTVlNzhhZTFlMzIyOQ.jpg',
following: [1],
posts: [
{
imageUrl: 'http://s3-media4.fl.yelpcdn.com/bphoto/ptpOBDdI95DxnbAcgig2WA/348s.jpg',
date: new Date(2012, 1, 6),
caption: 'here is a caption for peters post',
menuItem: '12290605'
},
{
imageUrl: 'http://s3-media2.fl.yelpcdn.com/bphoto/7oJFEUlICAy3Vur-aCF94Q/348s.jpg',
date: new Date(2015, 7, 2),
caption: 'here is a caption for peters second post',
menuItem: '24968808'
}
],
},
]
return User.createAsync(users);
};
connectToDb.then(function () {
User.findAsync({}).then(function (users) {
if (users.length === 0) {
return seedUsers();
} else {
console.log(chalk.magenta('Seems to already be user data, exiting!'));
process.kill(0);
}
}).then(function () {
console.log(chalk.green('Seed successful!'));
process.kill(0);
}).catch(function (err) {
console.error(err);
process.kill(1);
});
});