-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.js
420 lines (380 loc) · 12 KB
/
dev.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
const mongoose = require("mongoose");
const bcrypt = require("bcryptjs");
const User = require("../1.models/user");
const Category = require("../1.models/category");
const Community = require("../1.models/community");
const Member = require("../1.models/member");
const Channel = require("../1.models/channel");
const Post = require("../1.models/post");
function connectDb() {
console.log(" ===> Connect DB");
const conn = `mongodb://${process.env.MONGO_HOST}/${
process.env.MONGO_DATABASE
}?replicaSet=Cluster0-shard-0`;
mongoose
.connect(conn, {
useNewUrlParser: true,
keepAlive: 1,
reconnectTries: Number.MAX_VALUE,
w: "majority",
wtimeout: 10000,
ssl: true,
auth: { authSource: "admin" },
user: process.env.MONGO_USER,
pass: process.env.MONGO_PASSWORD
// server: { poolSize: 5 },
// replset: {rs_name: 'Cluster0-shard-0'},
})
.catch(err => {
console.log(err);
});
}
async function addUsers() {
console.log(addUsers.name, " => ");
await User.deleteMany({}, (err) => {
if (err) throw err;
});
const emails = [
"aa",
"bb",
"cc",
"dd",
"ff",
"ee",
"gg",
"hh",
"ss",
"zz",
"xx",
"oo",
"tt",
"qq",
"ww",
"rr",
"tt",
"yy",
"uu",
"ii"
];
for (let i = 0; i < emails.length; i++) {
let email = `${emails[i]}@gmail.com`;
let password = "123456";
await User.create({
email: email,
password: await bcrypt.hash(password, 12)
});
console.log(addUsers.name, " : ", email);
}
console.log("--------------------------------------------------------------");
}
async function addCategories() {
console.log("Add category =>");
await Category.deleteMany({}, (err) => {
if (err) throw err;
});
let res = await Category.create({
code: "TOP",
title: "Top communities",
description: "Top communities",
status: "on" //on off del appr
});
console.log("Inserted category :", res._doc.title);
res = await Category.create({
code: "DES",
title: "Design",
description: "Design",
status: "on" //on off del appr
});
console.log("Inserted category :", res._doc.title);
res = await Category.create({
code: "WEBDEV",
title: "Web development",
description: "Web development",
status: "on" //on off del appr
});
console.log("Inserted category :", res._doc.title);
res = await Category.create({
code: "TECH",
title: "Tech",
description: "Tech",
status: "on" //on off del appr
});
console.log("Inserted category :", res._doc.title);
res = await Category.create({
code: "LIFE",
title: "Life",
description: "Life",
status: "on" //on off del appr
});
console.log("Inserted category :", res._doc.title);
console.log("--------------------------------------------------------------");
}
async function getUsers() {
//'aa','bb','cc','dd','ff','ee','gg','hh','ss','zz','xx','oo','tt','qq','ww','rr','tt','yy','uu','ii'
const aa = await User.findOne({ email: "aa@gmail.com" }).lean();
const bb = await User.findOne({ email: "bb@gmail.com" }).lean();
const cc = await User.findOne({ email: "cc@gmail.com" }).lean();
const dd = await User.findOne({ email: "dd@gmail.com" }).lean();
const ff = await User.findOne({ email: "ff@gmail.com" }).lean();
const ee = await User.findOne({ email: "ee@gmail.com" }).lean();
const gg = await User.findOne({ email: "gg@gmail.com" }).lean();
const hh = await User.findOne({ email: "hh@gmail.com" }).lean();
const ss = await User.findOne({ email: "ss@gmail.com" }).lean();
const zz = await User.findOne({ email: "zz@gmail.com" }).lean();
const xx = await User.findOne({ email: "xx@gmail.com" }).lean();
const oo = await User.findOne({ email: "oo@gmail.com" }).lean();
const tt = await User.findOne({ email: "tt@gmail.com" }).lean();
const qq = await User.findOne({ email: "qq@gmail.com" }).lean();
const ww = await User.findOne({ email: "ww@gmail.com" }).lean();
const rr = await User.findOne({ email: "rr@gmail.com" }).lean();
return { aa, bb, cc, dd, ff, ee, gg, hh, ss, zz, xx, oo, tt, qq, ww, rr };
}
async function addCommunity() {
console.log(addCommunity.name, " =>");
await Community.deleteMany({}, (err) => {
if (err) throw err;
});
const { aa } = await getUsers();
const TOP = await Category.findOne({ code: "TOP" }).lean();
const DES = await Category.findOne({ code: "DES" }).lean();
const WEBDEV = await Category.findOne({ code: "WEBDEV" }).lean();
let res = await Community.create({
title: "How-That Suport",
alias: "how-that-suport",
description:
"How-That Suport is a community platform for the future. This community is a great place to ask questions, request features, report bugs, and chat with the How-That teams",
url: "howthat.com",
profilePhoto:'img/profile.jpg',
coverPhoto:'img/cover.jpg',
category: TOP,
creator: aa,
action: "read",
status: "on" //on off del appr
});
console.log(addCommunity.name, " : ", res._doc.title);
res = await Community.create({
title: "Zeit",
alias: "zeit",
description:
"Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.",
url: "https://zeit.co",
profilePhoto:'img/profile.jpg',
coverPhoto:'img/cover.jpg',
category: WEBDEV,
creator: aa,
action: "all",
status: "on" //on off del appr
});
console.log(addCommunity.name, " : ", res._doc.title);
res = await Community.create({
title: "Codesandbox",
alias: "codesandbox",
description:
"CodeSandbox is an online editor built for web applications, here you can talk about it or share your work!",
url: "https://codesandbox.io",
profilePhoto:'img/profile.jpg',
coverPhoto:'img/cover.jpg',
category: WEBDEV,
creator: aa,
action: "all",
status: "on" //on off del appr
});
console.log(addCommunity.name, " : ", res._doc.title);
res = await Community.create({
title: "React",
alias: "React",
description:
"A community of developers, designers and others who love React.js. ⚛️",
url: "https://reactjs.org",
profilePhoto:'img/profile.jpg',
coverPhoto:'img/cover.jpg',
category: WEBDEV,
creator: aa,
action: "all",
status: "on" //on off del appr
});
console.log(addCommunity.name, " : ", res._doc.title);
res = await Community.create({
title: "Figma",
alias: "figma",
description:
"Figma is the first collaborative UI design tool built in the browser. Join our growing community and kick off a conversation!",
url: "www.figma.com",
profilePhoto:'img/profile.jpg',
coverPhoto:'img/cover.jpg',
category: WEBDEV,
creator: aa,
action: "all",
status: "on" //on off del appr
});
console.log(addCommunity.name, " : ", res._doc.title);
console.log("--------------------------------------------------------------");
}
async function addChanel() {
console.log(addChanel.name, " =>");
await Channel.deleteMany({}, (err) => {
if (err) throw err;
});
const { aa, bb, cc } = await getUsers();
const howthat = await Community.findOne({ alias: "how-that-suport" }).lean();
let res = await Channel.create({
title: "General",
creator: aa,
community: howthat,
status: "on"
});
console.log(addChanel.name, " : ", res._doc.title);
res = await Channel.create({
title: "Suport",
creator: bb,
community: howthat,
status: "on"
});
console.log(addChanel.name, " : ", res._doc.title);
res = await Channel.create({
title: "News",
creator: cc,
community: howthat,
status: "on"
});
console.log(addChanel.name, " : ", res._doc.title);
console.log("--------------------------------------------------------------");
}
async function addMember() {
console.log(addMember.name, " =>");
await Member.deleteMany({}, (err) => {
if (err) throw err;
});
const {
aa,
bb,
cc,
dd,
ff,
ee,
gg,
hh,
ss,
zz,
xx,
oo,
tt,
qq,
ww,
rr
} = await getUsers();
const users = [
aa,
bb,
cc,
dd,
ff,
ee,
gg,
hh,
ss,
zz,
xx,
oo,
tt,
qq,
ww,
rr
];
const howthat = await Community.findOne({ alias: "how-that-suport" }).lean();
let channels = await Channel.find({ community: howthat }).lean();
channels = channels.map(c => {
return {
channel: c._id,
setting: "notice" // notice - mute
};
});
for (let i = 0; i < users.length; i++) {
// normal - team - blocked
let status = users[i].email.includes('aa') || users[i].email.includes('bb') || users[i].email.includes('cc') ? "team" : "normal";
const res = await Member.create({
comunity: howthat,
user: users[i],
channels: channels,
status: status
});
console.log(addMember.name," : ", res._doc.user);
}
console.log("--------------------------------------------------------------");
}
async function createPosts() {
console.log(createPosts.name, " =>");
await Post.deleteMany({}, (err) => {
if (err) throw err;
});
const {
aa,
bb,
cc,
dd,
ff,
ee,
gg,
hh,
ss,
zz,
xx,
oo,
tt,
qq,
ww,
rr
} = await getUsers();
const users = [
aa,
bb,
cc,
dd,
ff,
ee,
gg,
hh,
ss,
zz,
xx,
oo,
tt,
qq,
ww,
rr
];
const howthat = await Community.findOne({ alias: "how-that-suport" }).lean();
const channels = await Channel.find({ community: howthat._id }).lean();
// console.log("channels", channels);
for (let i = 0; i < users.length; i++) {
console.log(users[i].email, "posts : ");
for (let j = 0; j < channels.length; j++) {
// const test = `${users[i].email} - ${channels[j].title} - How to install packages that aren't on npm?`;
const res = await Post.create({
title: `${users[i].email} - ${channels[j].title} - How to install packages that aren't on npm?`,
exceprt: `Hi all - I've been struggling for a while now trying to install nodejs packages which aren't on npm. In my package.json, this syntax works fine on non-serverless deployments...`,
content: `<div class="markdown"><p class="style__Paragraph-hbwp71-18 ioJKJG">Hi all - I've been struggling for a while now trying to install nodejs packages which aren't on npm. In my package.json, this syntax works fine on non-serverless deployments:</p><pre class="prism-code language-json style__Line-hbwp71-17 hEkGzJ"><div class="token-line"><span class="token property">"@nbbj/package-internal"</span><span class="token operator">:</span><span class="token plain"> </span><span class="token string">"file:packages/nbbj-package-internal-2.5.1.tgz"</span><span class="token plain">.</span></div></pre><p class="style__Paragraph-hbwp71-18 ioJKJG">However I can't get that pattern to work on Now. I've also tried installing from private GitHub repositories with no success - it works just fine in all other deployments, but trying to do it in Now serverless and it can't find the file/package - even when equipped with the right access keys.</p><p class="style__Paragraph-hbwp71-18 ioJKJG">Any ideas how I can include a private package to be used during the build would be very helpful. We're trying to reduce monthly recurring costs, so we are being pushed away from being able to do private npm packages.</p></div>`,
status: 'on',
postType: 'doc',
commentStatus: 'on',
creator: users[i],
channel: channels[j],
comunity: howthat,
});
console.log(createPosts.name, " : ", res._doc.title);
}
}
console.log("--------------------------------------------------------------");
}
//===============================================================================================================================================================
connectDb();
(async () => {
await addUsers();
await addCategories();
await addCommunity();
await addChanel();
await addMember();
await createPosts();
console.log("end ...");
process.exit(0);
})();