-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseedData.js
More file actions
205 lines (176 loc) · 6.33 KB
/
seedData.js
File metadata and controls
205 lines (176 loc) · 6.33 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
'use strict';
/*
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.
Refer to the q documentation for why and how q.invoke is used.
*/
let mongoose = require('mongoose');
let connectToDb = require('./server/db');
let User = mongoose.model('User');
let Article = mongoose.model('Article');
let q = require('q');
let chalk = require('chalk');
let randomize = (arr) => {
return Math.floor(Math.random() * arr.length);
}
let getCurrentUserData = () => {
return q.ninvoke(User, 'find', {});
};
let seedUsers = () => {
let users = [
{
email: 'test@test.com',
password: '123',
role: 'admin',
profile: {
name: 'Tester',
},
},
{
email: 'qwe@qwe.com',
password: '123',
role: 'admin',
profile: {
name: 'Qwerty-Man'
},
},
{
email: 'asd@asd.com',
password: '123',
role: 'user',
profile: {
name: 'Hollow Tapes'
},
},
{
email: 'zxc@zxc.com',
password: '123',
role: 'user',
profile: {
name: 'Random Letters'
},
}
];
return q.invoke(User, 'create', users);
};
let seedArticles = (users) => {
let articles = [
{
name: 'Intro to ReactJS',
author: users[randomize(users)]._id,
content: markdown_text,
tags: ['react', 'es6', 'webpack']
},
{
name: 'Intro to Angular2',
author: users[randomize(users)]._id,
content: markdown_text,
tags: ['angular', 'es6', 'angular2']
},
{
name: 'AngularJS Fundamentals',
author: users[randomize(users)]._id,
content: markdown_text,
tags: ['angular', 'es6', 'webpack']
},
{
name: 'Advanced Directives in AngularJS',
author: users[randomize(users)]._id,
content: markdown_text,
tags: ['angular', 'es6', 'directives']
},
{
name: 'AngularJS Authentication',
author: users[randomize(users)]._id,
content: markdown_text,
tags: ['react', 'es6', 'webpack']
}
];
return q.invoke(Article, 'create', articles);
}
connectToDb.then(() => {
getCurrentUserData().then((users) => {
if (users.length === 0) {
return seedUsers();
} else {
console.log(chalk.magenta('Seems to already be user data, exiting!'));
process.kill(0);
}
}).then(() => {
return getCurrentUserData();
}).then((users) => {
return seedArticles(users);
}).then(() => {
return q.ninvoke(Article, 'find', {}).then((articleArr) => {
let promiseArr = articleArr.map((article) => {
User.findById(article.author).exec().then((user) => {
user.projects.push(article._id);
user.save().exec();
});
});
return q.all(promiseArr);
});
}).then(() => {
console.log(chalk.green('Seed successful!'));
process.kill(0);
});
}).catch((err) => {
console.error(err);
process.kill(1);
});
let markdown_text = `# Ut fugerat terrigenam sonent resoluta in nutrix
## Spectat Hesperien et nunc
Lorem markdownum parenti ut matris. Et retracto, non aniles partes, limite nos
peto et terrenaque ululare et illam. Magnique eodem, nec dicere suam nullo comas
adituque ut fugam ipsa sorore, ab. Damno et raro fuerunt nefanda Iovique capro
tendentem terreat sucis australem manum splendidaque pectore.
alert(shareware_dv_interpreter.whitelistOlapHard.redundancy_truncate_denial(
rpm_gopher_middleware), camelcase(10, dvrNtfs) +
supercomputerPdfWord.cybersquatterUri(throughput_cdn_session, 5,
mips), 2);
let firmwareMegapixel = 31;
desktop = hard_port_refresh;
if (disk_dvi(18, pup_hit_plug * viral_osd_cgi, 5)) {
directxCopyRuntime.jsf += ocr + viral_meta_permalink;
columnTcp = text_repeater_key(fsb_design_unmount);
file_bus_cyberbullying = hypertext_icio(mirrored_print_data);
} else {
station_compile(menu_barcraft_perl);
scraping = htmlProcessorWi.typeSystem.page(veronicaSequenceDriver(62396,
45));
exbibytePortBridge(-5, port_sync);
}
## Petere Nilus
Haec postquam caesarumque suus conantesque lucis; [nebula unum
solum](http://www.uselessaccount.com/), et fuerunt. Portus pervia res viscera
pater evehor conplevit similes graviore, causa. Nox triplici puppis Balearica
supremum servet relinquitur costumque tandem prius cursus; accipit voce aetas.
Commota quae potest levior voluisti obsceno votaque: frigida: fronti primum.
## Fit urget me vivit pudoris prodet haurire
Tela pendentibus sine, iamdudum deos positas infelix, numen circumfert ut fugit
os Quirini perque iacent! Facto et et meis madidisque adeste! *Poterat fera*,
tam viribus crinem. Nec dedit desint meritam neque. Quam enim *volvitur et
Aonides* insequitur intus tumulandus viro reverentia et Athon Delphos stivave
retexite.
## Est qua et fumo caesaries inmunibus
Consistere corpore **videt Sardibus**, rudi obductos de armis [sordidus
palustribus](http://www.youtube.com/watch?v=MghiBW3r65M) pudicos. Novam palmis
adii in nimium umeris, saecula difficilem solo nubilis ea perque cum; aere urbs,
tinnulaque. Est nisi gentem pendens conveniunt ardua, sum utve procul vitam
incepto tenebas consolor tellus, altae.
1. Prima refugis quorum umenti Hecate
2. Facit plectrumque tincta quod aliquem quam
3. Mater arboris
4. Et prima senilem sanguine
Troiana per vincla *ne* duae mandarat, animi cuncta **in reserato passu**
Fluctibus Agenore monet? Nec conatur innata lavere; longa nullos, dies deum
siccis incepto; vesper misit.`;