This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
forked from laddhasuneedhi/CS546Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seed.js
458 lines (384 loc) · 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
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// You can add and export any helper functions you want here - if you aren't using any, then you can just leave this file as is
/*
1. Create a band of your choice.
2. Log the newly created band. (Just that band, not all bands)
3. Create another band of your choice.
4. Query all bands, and log them all
5. Create the 3rd band of your choice.
6. Log the newly created 3rd band. (Just that band, not all bands)
7. Rename the first band
8. Log the first band with the updated name.
9. Remove the second band you created.
10. Query all bands, and log them all
11. Try to create a band with bad input parameters to make sure it throws errors.
12. Try to remove a band that does not exist to make sure it throws errors.
13. Try to rename a band that does not exist to make sure it throws errors.
14. Try to rename a band passing in invalid data for the newName parameter to make sure it throws errors.
15. Try getting a band by ID that does not exist to make sure it throws errors.
*/
import { dbConnection, closeConnection } from './BackEnd/config/mongoConnection.js';
const db = await dbConnection();
// Use the named exports as properties of the imported object
await db.dropDatabase();
import fs from 'fs';
import recData from './BackEnd/data/recommendations.js'
import {createUser,checkUser, getUser, updateUser} from './BackEnd/data/users.js';
import {createPost} from './BackEnd/data/posts.js'
import { uploadPhoto } from './BackEnd/data/photos.js';
import { createGroup, memberAdd, addRecommendationToGroup } from './BackEnd/data/groups.js';
//create a bunch of usrrs
let first_user = ""
let second_user = ""
let third_user = ""
let fourth_user = ""
let firstgroup
let secondgroup
let thirdgroup
try{
first_user = await createUser("Michael123", "Michael", "Smith", "[email protected]", "Sunnu@3030", "1990-5-30")
}catch(e){
console.log(e)
}
try{
firstgroup =await createGroup("go eat", first_user._id)
}catch(e){
console.log(e)
}
try{
second_user = await createUser("Sarah12", "sarah", "parker", "[email protected]", "Crazy@123", "1995-5-30")
}catch(e){
console.log(e)
}
try{
secondgroup =await createGroup("go eat 2", first_user._id)
}catch(e){
console.log(e)
}
try{
thirdgroup =await createGroup("run run", second_user._id)
}catch(e){
console.log(e)
}
try{
third_user = await createUser("Fuslie12", "leslie", "chen", "[email protected]", "Crazy@123", "1992-10-11")
}catch(e){
console.log(e)
}
try{
await createGroup("run run run", third_user._id)
}catch(e){
console.log(e)
}
try{
fourth_user = await createUser("Jennierubyjane", "jenny", "kim", "[email protected]", "Crazy@123", "1996-10-11")
}catch(e){
console.log(e)
}
try{
await memberAdd(firstgroup._id,second_user._id)
}catch(e){
console.log(e)
}
try{
await memberAdd(firstgroup._id,third_user._id)
}catch(e){
console.log(e)
}
let update_first_user = ""
let profile_img_src = "/public/img/filled_heart.jpg"
try{
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/filled_heart.png');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/png'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let getphoto = await uploadPhoto(photo_obj)
let updateduser = await updateUser(first_user._id, first_user.username, first_user.email, first_user.userPosts, first_user.userStreak, "trying to live a healthy fulfilling life", first_user.groupsOwned, first_user.groupMembers, getphoto, ["Work out", "stay fit", "get healthy"], first_user.following, first_user.followers)
}catch(e){
console.log(e)
}
try{
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/sarah.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let getphoto = await uploadPhoto(photo_obj)
let secondupdate = await updateUser(second_user._id, second_user.username, second_user.email, second_user.userPosts, second_user.userStreak, "outdoorsy person and health freak!", second_user.groupsOwned, second_user.groupMembers, getphoto, ["hike the mt.everest", "run a 10k"], second_user.following, second_user.followers)
}catch(e){
console.log(e)
}
try{
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/fuslie.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let getphoto = await uploadPhoto(photo_obj)
let thirdupdate = await updateUser(third_user._id, third_user.username, third_user.email, third_user.userPosts, third_user.userStreak, "Happy go lucky person who wants a nice summer body", third_user.groupsOwned, third_user.groupMembers, getphoto, ["do pilates"], third_user.following, third_user.followers)
}catch(e){
console.log(e)
}
try{
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/girlpink.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let getphoto = await uploadPhoto(photo_obj)
let fourthupdate = await updateUser(fourth_user._id, fourth_user.username, fourth_user.email, fourth_user.userPosts, fourth_user.userStreak, "Just vibes tbh", fourth_user.groupsOwned, fourth_user.groupMembers, getphoto, [], fourth_user.following, fourth_user.followers)
}catch(e){
console.log(e)
}
//get the post stuff
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/running-guy-on-road.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(first_user._id, "first day out", "running", "ran 5 miles", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/mountaintop.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(first_user._id, "at the mountain", "running", "ran 5 miles", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/OIP.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(second_user._id, "working out", "lifting", "worked out so much today", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/walking.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(second_user._id, "working out", "lifting", "worked out so much today", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/kayaking.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(third_user._id, "went kayaking", "other", "worked out so much today", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/mountainclimbing.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(third_user._id, "tb to mountain climbing", "other", "had a blast!", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/running-guy-on-road.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(fourth_user._id, "love running with family", "running", "good workout", list, [] )
}catch(e){
console.log(e)
}
try{
let list = []
let photo_obj = {}
let imageBuffer = fs.readFileSync('public/img/OIP.jpg');
let original_name = profile_img_src
let encoding = imageBuffer.size;
let mimeType = 'image/jpg'
photo_obj.fieldname = 'photo'
photo_obj.originalname = original_name
photo_obj.buffer = imageBuffer
photo_obj.encoding = encoding
photo_obj.mimetype = mimeType
let uploadphoto = await uploadPhoto(photo_obj)
list.push(uploadphoto)
let uploadpost = await createPost(fourth_user._id, "working out", "lifting", "tiring", list, [] )
}catch(e){
console.log(e)
}
try{
let workoutName = "Bench Press"
let equipment = "Bar"
let duration = "20"
let level = 'intermediate'
let reps = '15'
let rounds = '3'
let tags = 'Chest'
await recData.createRec(workoutName,equipment,duration,level,reps,rounds,tags);
}catch(e){
console.log(e)
}
try{
let workoutName = "Dip"
let equipment = "Hang"
let duration = "15"
let level = 'advanced'
let reps = '12'
let rounds = '4'
let tags = 'Back'
await recData.createRec(workoutName,equipment,duration,level,reps,rounds,tags);
}catch(e){
console.log(e)
}
try{
let workoutName = "Pull up"
let equipment = "Hang"
let duration = "15"
let level = 'intermediate'
let reps = '15'
let rounds = '4'
let tags = 'Back'
await recData.createRec(workoutName,equipment,duration,level,reps,rounds,tags);
}catch(e){
console.log(e)
}
try{
let workoutName = "Sit up"
let equipment = "None"
let duration = "10"
let level = 'beginner'
let reps = '15'
let rounds = '2'
let tags = 'Others'
await recData.createRec(workoutName,equipment,duration,level,reps,rounds,tags);
}catch(e){
console.log(e)
}
try{
let workoutName = "Curl"
let equipment = "Dumbells"
let duration = "20"
let level = 'intermediate'
let reps = '15'
let rounds = '4'
let tags = 'Others'
await recData.createRec(workoutName,equipment,duration,level,reps,rounds,tags);
}catch(e){
console.log(e)
}
try{
await addRecommendationToGroup(firstgroup._id,"Curl", "Dumbells", "20", 'intermediate', '15', '4', 'Others')
}catch(e){
console.log(e)
}
try{
await addRecommendationToGroup(firstgroup._id,"Dip",
"Hang",
"15",
'advanced',
'12',
'4',
'Back')
}catch(e){
console.log(e)
}
try{
await addRecommendationToGroup(secondgroup._id,"CurlCurl", "Dumbells", "20", 'intermediate', '15', '4', 'Others')
}catch(e){
console.log(e)
}
try{
await addRecommendationToGroup(thirdgroup._id,"CurlTriceps", "Dumbells", "20", 'intermediate', '15', '4', 'Others')
}catch(e){
console.log(e)
}
await closeConnection();