-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueModule.js
More file actions
111 lines (98 loc) · 3 KB
/
QueueModule.js
File metadata and controls
111 lines (98 loc) · 3 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
const Room = require("./models/Room");
const roomDocList = require("./roomModule").roomDocList;
function generateRoomID(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var Queue = (module.exports = {
/////////////////////QUEUE LISTS/////////////////////////////
uwList: [],
uoftList: [],
quList: [],
macList: [],
uwoList: [],
oList: [],
dfList: [],
///////////////////ADD AND DEL FUNCTIONS////////////////////
getUniversityQueue: function (university) {
switch(university) {
case "University of Waterloo":
//console.log("uList is Waterloo");
return this.uwList;
case "University of Toronto":
//console.log("uList is Toronto");
return this.uoftList;
case "Queen's University":
//console.log("uList is Queen's");
return this.quList;
case "McMaster University":
//console.log("uList is McMaster");
return this.macList;
case "Western University":
//console.log("uList is Western");
return this.uwoList;
case "University of Ottawa":
//console.log("uList is Ottawa");
return this.oList;
default:
//console.log("uList is Waterloo");
return this.uwList;
}
},
addUser: function (newUser) {
uList = this.getUniversityQueue(newUser.university);
if (!uList.includes(newUser)) {
uList.push(newUser);
if (uList.length > 1) { //matching algorithm
const matchedUser = uList[0];
uList.splice(0, 1);
const i = uList.indexOf(newUser);
uList.splice(i, 1);
//generate roomid and room
const roomID = generateRoomID(16);
const newRoom = new Room({
name1: newUser.name,
name2: matchedUser.name,
email1: newUser.email,
email2: matchedUser.email,
program1: newUser.program,
program2: matchedUser.program,
interests1: newUser.interests,
interests2: matchedUser.interests,
//commonInterests: commonInterests,
roomId: roomID,
});
console.log("creating room for two users: " + newUser.name + " " + matchedUser.name);
console.log("roomID is: " + roomID);
roomDocList.push(newRoom)
//append newRoom to room collection
newRoom.save((err) => {
if (err) {
console.log(err);
}
});
}
return true;
}
else {
return false;
}
},
delUser: function (user) {
uList = this.getUniversityQueue(user.university);
let index = uList.findIndex((s) => s.email == user.email); //find user from uList
if (index >= 0) {
uList.splice(index, 1);
return true;
}
else {
return false;
}
},
});