-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddData.js
48 lines (43 loc) · 2.12 KB
/
addData.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
const express = require('express');
const router = express.Router();
const Team = require('./models/TeamModel');
const User = require('./models/UserModel');
const Member = require('./models/MemberModel');
router.post('/', async (req, res) => {
const data = req.body;
data.forEach( async (element) => {
const {teamName, TeamLeaderName, TeamLeaderEmail, Member1Name, Member1Email, Member2Name, Member2Email, Member3Name, Member3Email, totalPeople} = element;
const team = Team({TeamName : teamName, RoundTwoAttempted : false, RoundOneAttempted : false,RoundTwoAttempted : false, RoundOneStarted : false, RoundTwoStarted : false ,Members : [],AttemptsDone : 0, leader : {}, RoundOnePoints : 0, RoundTwoPoints : 0});
const leader = User({email : TeamLeaderEmail, name : TeamLeaderName, photoURL : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSlR3hMw_3daUL3Uhr5Y3uJh_kMaYzyqQhhPA&usqp=CAU"});
const leaderM = Member({User : leader, isLeader : true, isApproved : true, teamID : team});
team.addMember(leaderM, true);
await leader.save();
await leaderM.save();
console.log(TeamLeaderName)
for (j = 0; j < totalPeople - 1; j++){
var memberName;
var memberEmail;
if (j == 0){
memberName = Member1Name;
memberEmail = Member1Email;
}
else if (j == 1){
memberName = Member2Name;
memberEmail = Member2Email;
}
else{
memberName = Member3Name;
memberEmail = Member3Email;
}
const user = User({email : memberEmail, name : memberName, photoURL : "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSlR3hMw_3daUL3Uhr5Y3uJh_kMaYzyqQhhPA&usqp=CAU"});
const member = Member({User : user, isLeader : false, isApproved : true, teamID : team});
team.addMember(member);
await user.save();
await member.save();
console.log(memberName);
}
await team.save();
});
res.json("added");
});
module.exports = router;