forked from SE-GUC/ERROR-404
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn.js
610 lines (532 loc) · 17.2 KB
/
fn.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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
const axios = require("axios");
const Article = require("./models/Article");
const Articles = require("./routes/api/Articles");
const User = require("./models/User");
const Users = require("./routes/api/Users");
const functions = {
getUsers: async () => {
const Users = await axios.get("http://localhost:3000/api/Users");
return Users;
},
getUserByIdFound: async () => {
const user = User.findOne();
const userId = user._id;
const userFound = await axios.get(
"http://localhost:3000/api/Users/" + userId
);
return userFound;
},
getAllClubs: async () => {
const clubs = await axios.get("http://localhost:3000/api/Clubs");
return clubs;
},
getAllContent: async () => {
const content = await axios.get("http://localhost:3000/api/Contents");
return content;
},
getAllContent: async () => {
const content = await axios.get("http://localhost:3000/api/Contents");
return content;
},
createContent: async content => {
const newContent = await axios.post(
"http://localhost:3000/api/Contents",
content
);
return newContent;
},
updateContent: async (id, updatedData) => {
const updatedContent = await axios.put(
`http://localhost:3000/api/Contents/${id}`,
updatedData
);
return updatedContent;
},
deleteContent: async id => {
const deletedContent = await axios.delete(
`http://localhost:3000/api/Contents/${id}`
);
return deletedContent;
},
viewcontent: async () => {
const getuser = await axios.get("http://localhost:3000/api/Contents/");
return getuser;
},
viewcertaincontent: async () => {
const allContent = await axios.get("http://localhost:3000/api/Contents");
const contId = allContent.data.data[0]._id;
const getcertainuser = await axios.get(
"http://localhost:3000/api/Contents/" + contId
);
return getcertainuser;
},
//-------------------------------------------------------------------
//------------------------------------------------------------------
//getingg all users
getUsers: async () => {
const users = await axios.get("http://localhost:3000/api/Users");
return users;
},
//------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
//Testing that TIQ admins are able to create new users
createUser: async newU => {
const newUser = await axios.post(
"http://localhost:3000/api/Users/register",
newU
);
return newUser;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
updateUser: async (id, updateUser) => {
const User = await axios.put(
"http://localhost:3000/api/Users/" + id,
updateUser
);
return User;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
deleteUser: async id => {
const deleteduser = await axios.delete(
"http://localhost:3000/api/Users/" + id
);
return deleteduser;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
getUserById: async id => {
const getUser = await axios.get("http://localhost:3000/api/Users/" + id);
return getUser;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
// Testing that users are able to view certain Articles with id=1
getArticleById: async id => {
const article = await axios.get("http://localhost:3000/api/Articles/" + id);
return article;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
// // Testing that users are able to view Articles
getArticles: async () => {
//done
const articles = await axios.get("http://localhost:3000/api/Articles");
return articles;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
// //Testing that TIQ admins are able to create new motions on the Debate live
createMotion: async motion => {
//done
const newMotion = await axios.post(
"http://localhost:3000/api/Chatbars/create",
motion
);
return newMotion;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
getDebateLive: async () => {
const debateLives = await axios.get("http://localhost:3000/api/Chatbars");
return debateLives;
},
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
getDebateLiveByIdFor: async id => {
const debateLivesFor = await axios.get(
"http://localhost:3000/api/Chatbars/" + id
);
return debateLivesFor;
},
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
// //Testing that the number of responses are always updated
updateNumberOfResponses: async (id, response) => {
const newO = await axios.put(
"http://localhost:3000/api/Chatbars/for/" + id,
{
forResponses: [response]
}
);
return newO;
},
// getArticles: async () => {
// const Articles = await axios.get('http://localhost:3000/api/Articles/')
// return Articles
// },
createArticles: async article => {
const newArticle = await axios.post(
"http://localhost:3000/api/Articles/create",
{
title: article.title,
description: article.description,
author: article.author,
date: article.date
}
);
return newArticle;
},
updateArticles: async (id, updatedData) => {
const updatedArticle = await axios.put(
"http://localhost:3000/api/Articles/" + id,
{
title: updatedData.title,
description: updatedData.description,
author: updatedData.author,
date: updatedData.date
}
);
return updatedArticle;
},
deleteArticles: async id => {
const deleteArticle = await axios.delete(
"http://localhost:3000/api/Articles/" + id
);
return deleteArticle;
},
getDebateLive: async () => {
const debateLives = await axios.get("http://localhost:3000/api/Chatbars/");
return debateLives;
},
getDebateLiveById: async id => {
const debateLives = await axios.get(
"http://localhost:3000/api/Chatbars/" + id
);
return debateLives;
},
deleteDebateLive: async id => {
const deleteDebateLive = await axios.delete(
"http://localhost:3000/api/Chatbars/" + id
);
return deleteDebateLive;
},
getClubById: async id => {
const club = await axios.get(`http://localhost:3000/api/Clubs/${id}`);
return club;
},
getAllClubs: async () => {
const clubs = await axios.get("http://localhost:3000/api/Clubs");
return clubs;
},
createClub: async club => {
const newClub = await axios.post("http://localhost:3000/api/Clubs", club);
return newClub;
},
updateClub: async (id, updatedData) => {
const updatedClub = await axios.put(
`http://localhost:3000/api/Clubs/${id}`,
updatedData
);
return updatedClub;
},
deleteClub: async id => {
const deletedClub = await axios.delete(
`http://localhost:3000/api/Clubs/${id}`
);
return deletedClub;
},
getDebates: async () => {
const debates = await axios.get("http://localhost:3000/api/Debates");
return debates;
},
createDebate: async debate => {
const newDebate = await axios.post("http://localhost:3000/api/Debates", {
title: debate.title,
category: debate.category,
date: debate.date,
info: debate.info,
description: debate.description
});
return newDebate;
},
deleteDebate: async id => {
const response = await axios.delete(
`http://localhost:3000/api/Debates/${id}`
);
return response;
},
updateDebate: async (id, debate) => {
const response = await axios.put(
`http://localhost:3000/api/Debates/${id}`,
{
title: debate.title,
category: debate.category,
date: debate.date,
info: debate.info,
description: debate.description
}
);
return response;
},
getDebateById: async id => {
const response = await axios.get(`http://localhost:3000/api/Debates/${id}`);
return response;
},
createInvalidDebate: async () => {
const newDebate = await axios.post("http://localhost:3000/api/Debates", {
title: "DebateTest",
category: "Updated Category",
info: "Debate Created in the Test",
description: "Creating this debate to test"
});
return newDebate;
},
updateInvalidDebate: async id => {
const response = await axios.put(
`http://localhost:3000/api/Debates/${id}`,
{
title: "D",
category: "Updated Category",
date: "1-1-2019",
info: "Updated by Invalid Schema",
description: "Updating this debate to test"
}
);
return response;
},
getInvalidPage: async () => {
const response = await axios.get("http://localhost:3000/apv/Debates");
return response;
},
getUsers: async () => {
const Users = await axios.get("http://localhost:3000/api/Users");
return Users;
},
getUserByIdFound: async () => {
//const user = User.findOne()
const allUsers = await axios.get("http://localhost:3000/api/Users");
const userId = allUsers.data.data[0]._id;
const userFound = await axios.get(
"http://localhost:3000/api/Users/" + userId
);
return userFound;
},
getUserByIdNotFound: async () => {
const user = await axios.get("http://localhost:3000/api/Users/1");
return user;
},
updateUserScore: async () => {
const user = await axios.post("http://localhost:3000/api/Users/register", {
type: "member",
firstName: "Nadin ",
lastName: "7ob 3omry",
birthDate: "12-11-1998",
bio: "heheehhe",
email: "[email protected]",
password: "boooom1234",
clubs: ["tiq"],
house: "pegasus"
});
const userId = user.data.data._id;
const updated = await axios.put(
"http://localhost:3000/api/Users/" + userId + "/7"
);
const deleteCreated = await axios.delete(
"http://localhost:3000/api/Users/" + userId
);
return updated;
},
deleteUserSuccess: async () => {
//const user = await createUserTesting()
const user = await axios.post("http://localhost:3000/api/Users/register", {
type: "member",
firstName: "Nadin ",
lastName: "7ob 3omry",
birthDate: "12-11-1998",
bio: "heheehhe",
email: "[email protected]",
password: "boooom1234",
clubs: ["tiq"],
house: "pegasus"
});
const userId = user.data.data._id;
const deleteduser = await axios.delete(
"http://localhost:3000/api/Users/" + userId
);
return deleteduser;
},
getAllClubs: async () => {
const clubs = await axios.get("http://localhost:3000/api/Clubs");
return clubs;
},
getAllContent: async () => {
const content = await axios.get("http://localhost:3000/api/Contents");
return content;
},
getAllContent: async () => {
const content = await axios.get("http://localhost:3000/api/Contents");
return content;
},
createContent: async content => {
const newContent = await axios.post(
"http://localhost:3000/api/Contents",
content
);
return newContent;
},
updateContent: async (id, updatedData) => {
const updatedContent = await axios.put(
`http://localhost:3000/api/Contents/${id}`,
updatedData
);
return updatedContent;
},
deleteContent: async id => {
const deletedContent = await axios.delete(
`http://localhost:3000/api/Contents/${id}`
);
return deletedContent;
},
viewcontent: async () => {
const getuser = await axios.get("http://localhost:3000/api/Contents/");
return getuser;
},
viewcertaincontent: async () => {
const allContent = await axios.get("http://localhost:3000/api/Contents");
const contId = allContent.data.data[0]._id;
const getcertainuser = await axios.get(
"http://localhost:3000/api/Contents/" + contId
);
return getcertainuser;
},
searchDebatesbycategory: async () => {
const newDebate=await axios.post('http://localhost:3000/api/Debates',{
title : "smoking",
category : "health",
date : "12-21-2001",
description : "gdhakvcladbhc",
info : "aksnansd;akn"
})
const debate = await axios.get('http://localhost:3000/api/Debates/Search/health')
return debate
},
searchArticlesByTitle:async id =>{
const newArticle = await axios.post("http://localhost:3000/api/Articles/create",{
title: "sksl are jdsk",
description: "dsjk",
author: "djsk",
date: "12-21-2001"
})
const article = await axios.get("http://localhost:3000/api/Articles/Search/are/") //a7ot id mazboot
return article
},
searchMotionsByTitle:async id =>{
const newChatBar = await axios.post("http://localhost:3000/api/Chatbars/create",{
debateLiveTitle: "dsjk are djsk",
date: "12-21-2001"
})
const chatBar = await axios.get("http://localhost:3000/api/Chatbars/search/are/") //a7ot id mazboot
return chatBar
},
getQuestionsAdmin:async id =>{
const question = await axios.get("http://localhost:3000/api/Questions/admin/") //a7ot id mazboot
return question
},
getQuestions:async id =>{
const question = await axios.get("http://localhost:3000/api/Questions/allQuestions/admin/") //a7ot id mazboot
return question
},
getQById: async id => {
const Q = await axios.get('http://localhost:3000/api/Questions/'+id)
return Q
},
deleteQuestions: async id=>{
const deletedQuestion = await axios.delete("http://localhost:3000/api/Questions/"+id) //a7ot id mazboot
return deletedQuestion
},
askQuestion:async id =>{
const question = await axios.post("http://localhost:3000/api/Questions/ask/",{ //a7ot id mazboot
question: "how are you ?",
user:"blala"
})
return question
},
answerQuestion:async id =>{
const question = await axios.put("http://localhost:3000/api/Questions/answerquestion/"+id,{ //a7ot id mazboot
answer:"nouran"
})
return question
},
getAnswers:async id =>{
const answer = await axios.get("http://localhost:3000/api/Questions/user/"+id) //a7ot id mazboot
return answer
},
getFAQs: async () => {
const FAQs = await axios.get('http://localhost:3000/api/FAQs/')
return FAQs
},
deleteFAQs: async id=>{
const deletedFAQ = await axios.delete("http://localhost:3000/api/FAQs/"+id) //a7ot id mazboot
return deletedFAQ
},
getFAQById: async id => {
const FAQs = await axios.get('http://localhost:3000/api/FAQs/'+id)
return FAQs
},
createFAQs:async () => {
const newFAQ = await axios.post("http://localhost:3000/api/FAQs/add",{
question:"how are you ?",
answer: "meh",
})
return newFAQ
},
updateFAQs:async id =>{
const updatedFAQ = await axios.put("http://localhost:3000/api/FAQs/edit/"+id,{ //a7ot id mazboot
question: "what's your name",
answer:"nouran"
})
return updatedFAQ
} ,
searchUsersByName: async () => {
const newUser=await axios.post('http://localhost:3000/api/Users/register',{
type:"alumni",
firstName:"nouran",
lastName:"KAMAAAAAAAL",
birthDate: "12-21-2001",
bio:"heeee",
email: "[email protected]",
password: "jdknnuuniik",
clubs:["scs"],
house:"Pegasus",
din:"1/1/2010",
dor:"3/4/2013"
})
const user = await axios.get('http://localhost:3000/api/Users/Search/nouran')
const id=newUser.data.data._id
const deletedUser = await axios.delete("http://localhost:3000/api/Users/"+id)
return user
},
searchUsersByType: async () => {
const newUser=await axios.post('http://localhost:3000/api/Users/register',{
type:"alumni",
firstName:"nouran",
lastName:"KAMAAAAAAAL",
birthDate: "12-21-2001",
bio:"heeee",
email: "[email protected]",
password: "jdknnuuniik",
clubs:["scs"],
house:"Pegasus",
din:"1/1/2010",
dor:"3/4/2013"
})
const id=newUser.data.data._id
const user = await axios.get('http://localhost:3000/api/Users/Search/alumni')
const deletedUser = await axios.delete("http://localhost:3000/api/Users/"+id)
return user
},
searchDebatesbydate: async () => {
const newDebate=await axios.post('http://localhost:3000/api/Debates',{
title : "smoking",
category : "health",
date : "12-21-2001",
description : "gdhakvcladbhc",
info : "aksnansd;akn"
})
const debate = await axios.get('http://localhost:3000/api/Debates/searchbydate/12-21-2001')
return debate
},
};
module.exports = functions;