forked from Johnny-Q/Hack-It-Better
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
133 lines (111 loc) · 3.63 KB
/
server.js
File metadata and controls
133 lines (111 loc) · 3.63 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
122
123
124
125
126
127
128
129
130
131
132
133
const express = require("express");
const bodyParser = require("body-parser");
const io = require("socket.io")(4000);
const { Ticket } = require("./ticket");
const app = express();
app.engine("html", require("ejs").renderFile);
app.use(express.static("public"));
app.use(bodyParser.json());
var idCounter = 0;
//views
app.get("/", function (req, res) {
res.render("test.html");
});
app.get("/teacher", function (req, res) {
res.render("teacher_ticket.html");
});
app.get("/student", function (req, res) {
res.render("student_dashboard.html");
});
app.get("/teacher", function (req, res) {
res.render("teacher_ticket.html");
});
app.get("/chat", function (req, res) {
res.render("studyGroup.html");
});
//api endpoints RESTful
//ticketing
app.get("/ticket", function (req, res) {
console.log(tickets);
res.send(JSON.stringify(tickets));
// res.sendStatus(200);
});
app.post("/ticket", function (req, res) {
//json params: author, body, tags, className
var { author, body, subject, parentTag, childTag, className } = req.body;
tickets[idCounter] = new Ticket(idCounter, author, subject, body, className, parentTag, childTag);
console.log("create ticket", subject, body);
idCounter++;
res.send(tickets[idCounter-1]);
});
app.put("/ticket", function (req, res) {
//response to ticket
var { response } = req.body;
//get id of ticket
var { id } = req.body;
console.log(response, id);
tickets[id].close(response);
res.sendStatus(200);
});
app.delete("/ticket", function (req, res) {
});
//realtime chatting
const groups = {};
const users = {}
io.on('connection', socket => {
socket.on("join-group", (groupID, name) => {
console.log("join-group", groupID, name);
socket.join(groupID);
socket.to(groupID).broadcast.emit("user-connected", name);
// socket.on('new-user', name => {
// users[socket.id] = name
// console.log("new user", name);
// socket.broadcast.emit('user-connected', name)
// })
socket.on('send-chat-message', message => {
socket.to(groupID).broadcast.emit('chat-message', { "message": message, "name": name });
});
// socket.on('disconnect', () => {
// socket.to(groupID).broadcast.emit('user-disconnected', users[socket.id]);
// delete users[socket.id];
// })
})
});
//keys would be class
//key to array of tickets
//parent tags
// ->child tags
// openTickets.Math.worksheet1
//openTickets["Math"]["worksheet1"][q1].push;
var classes = {
"science":{
"assignments":[],
"chats":[]
},
"math":{
"assignments":["worksheet1", "worksheet2", "test"],
"chats":[]
},
"english":{
"assignments":[],
"chats":[]
},
"economics":{
"assignments":[],
"chats":[]
}
};
//ticket id to actual ticket so we can access it better
var tickets = {};
tickets[0] = new Ticket(0, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet1", "q1");
tickets[1] = new Ticket(1, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet1", "q1");
tickets[2] = new Ticket(2, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet2", "q1");
tickets[3] = new Ticket(3, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet1", "q1");
tickets[4] = new Ticket(4, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet2", "q1");
tickets[5] = new Ticket(5, "johnny", "subject", "alskdjfaslkdjf", "math", "worksheet1", "q1");
for(var i = 0;i < 6; i++){
tickets[i].close("reeeeee");
}
app.listen(3000, function () {
console.log("listening on http://localhost:3000");
});