forked from Dixontirtayadi/Teamster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
122 lines (108 loc) · 3.67 KB
/
Copy pathserver.js
File metadata and controls
122 lines (108 loc) · 3.67 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
112
113
114
115
116
117
118
119
120
121
var express = require('express')
var app = express();
var database = require('./utils/database');
var path = require('path');
var grouper = require('./utils/groups');
const PORT = process.env.PORT || 3000;
app.use(express.static(__dirname + `/webpage`));
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/webpage/index.html'));
res.end;
})
app.get('/hi', function (req, res) {
res.send('Hello');
res.end;
})
app.get('/class', function (req, res) { //enters if user put in classID in start page
var info = req.query;
res.sendFile(path.join(__dirname + '/webpage/memberInfo.html'));
res.end;
})
app.get('/class/students', function (req, res) { //enters if student enters userId and email
var info = req.query;
// console.log("student = " + info);
if (database.addStudent(info.cID, info.sID, info.sEMAIL) == "doesn't exist!") {
res.sendFile(path.join(__dirname + '/404'));
} else {
const status = database.getStatus(info.cID);
console.log(status);
if(status === "off") {
console.log("1");
res.sendFile(path.join(__dirname + '/webpage/waitingroom.html'));
} else if (status === "short") {
console.log("2" + status);
res.sendFile(path.join(__dirname + '/webpage/questions.html'));
} else {
console.log("3");
res.sendFile(path.join(__dirname + '/webpage/murdermystery.html'));
}
}
res.end;
})
app.get('/class/teachers/game', function (req, res) { //enters when create room is entered. Choose game here
var info = req.query;
// console.log("student = " + info);
// if (!database.addClass(info.cID) == "exists!") {
database.addClass(info.cID);
console.log("HERE");
res.sendFile(path.join(__dirname + '/webpage/gameDuration.html'));
// }
res.end;
})
app.get('/class/teachers/game/short', function (req, res) { //enters when short game is chosen
var info = req.query;
// console.log("student = " + info);
// if (!database.addClass(info.cID) == "exists!") {
database.turnOn(info.cID, "short");
console.log("turned " + info.cID + " " + database.getStatus(info.cID));
res.sendFile(path.join(__dirname + '/webpage/waitingForResponses.html'));
// }
res.end;
})
app.get('/submit', function (req, res) {
var info = req.query;
database.addAnswer(info.cID, info.sID, info.answer);
res.sendFile(path.join(__dirname + '/webpage/thankYou.html'))
res.end;
})
// Helene
app.get('/class/students/murdermystery', function (req, res) { //classID=...&studentID=...&answers
var info = req.query;
console.log("murdermystery game is running");
database.turnOn(info.cID, "long");
console.log("turned " + info.cID + " " + database.getStatus(info.cID));
res.sendFile(path.join(__dirname + '/webpage/murdermystery.html'));
res.end;
})
// Helene
app.get('/analyzeResult', function (req, res) { //classID=...&groupSize=...
res.sendFile(path.join(__dirname + "/webpage/breakoutSize.html"));
res.end;
})
app.get('/analyze', function(req, res) {
res.sendFile(path.join(__dirname + "/webpage/groupedResults.html"));
})
app.get('/getData', function (req, res) {
res.send(printMap());
})
app.get('/formGroups', function (req, res) { //classID=...&groupSize=...
var cid = req.query.classID;
var groupSize = req.query.maxNum;
console.log(groupSize);
grouper(database.data.get(cid), groupSize).then((group) => {
res.send(group);
});
database.data.delete(cid);
res.end;
})
function printMap() {
let jsonObject = {};
database.data.forEach((value, key) => {
jsonObject[key] = value
});
return (JSON.stringify(jsonObject));
}
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});