-
Notifications
You must be signed in to change notification settings - Fork 0
/
protectedRoutes.js
195 lines (173 loc) · 5.7 KB
/
protectedRoutes.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
const express = require("express");
const router = express.Router();
const db = require("./dbFunctions");
const moment = require("moment");
// const joi = require("joi");
// const randomizer = require("randomatic");
// const nodemailer = require("nodemailer");
router.get("/", async (req, res) => {
try {
let user = await db.getMentor(req.decoded);
delete user.password
res.status(200).json(user);
} catch (err) {
console.log(err);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/test-twilio", async (req, res) => {
try {
let test = await db.testTwilio();
console.log(test)
res.status(200).end();
} catch (err) {
console.log(err);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/user", async (req, res) => {
try {
let user = await db.getMentor(req.decoded);
delete user.password
res.status(200).json(user);
} catch (err) {
console.log(err);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/users", async (req, res) => {
try {
const users = await db.getMentors();
res.status(200).json(users);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
// Maybe have some control flow that can use the sender ID or email and the recipient ID or email
router.post("/message", async (req, res) => {
req.body.sender = req.session.user.id
// req.body.timeReceived = moment().format('YYYY/MM/D hh:mm:ss SSS')
req.body.timeReceived = moment().format('YYYY/MM/D')
console.log(req.body)
try {
const message = await db.submitMessage(req.body);
res.status(200).json(message);
} catch (err) {
console.log(err.message)
res.status(500).json({ message: `Server error`, error: err });
}
});
//{ [Error: SQLITE_ERROR: table usersmessages has no column named message] errno: 1, code: 'SQLITE_ERROR' }
router.get("/get-messages", async (req, res) => {
try {
const messages = await db.getOwnMessages(req.decoded);
res.status(200).json(messages);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/get-groups", async (req, res) => {
try {
const groups = await db.getOwnGroups(req.decoded);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/get-clients", async (req, res) => {
try {
const groups = await db.getOwnClients(req.decoded);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/get-all-clients", async (req, res) => {
try {
const groups = await db.getAllClients();
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/get-regional-clients", async (req, res) => {
try {
const groups = await db.getRegionalClients(req.decoded);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.post("/add-clients", async (req, res) => {
try {
const groups = await db.addClient(req.body);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.post("/groupclient", async (req, res) => {
try {
const groups = await db.addClient(req.decoded,req.body);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.post("/create-group", async (req, res) => {
try {
const groups = await db.createGroup(req.decoded,req.body);
res.status(200).json(groups);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/get-events", async (req, res) => {
try {
const events = await db.getEvents();
res.status(200).json(events);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
// router.get("/get-groups-events", async (req, res) => {
// try {
// const groupsEvents = await db.setGroupEvent(req.decoded);
// res.status(200).json(groupsEvents);
// } catch (err) {
// console.log(err.message);
// res.status(500).json({ message: `Server error`, error: err });
// }
// });
router.post("/set-group-event", async (req, res) => {
try {
const groupEvent = await db.setGroupEvent(req.body);
res.status(200).json(groupEvent);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.post("/set-group-event-remind", async (req, res) => {
try {
const groupEvent = await db.setGrEvRemind(req.body);
res.status(200).json(groupEvent);
} catch (err) {
console.log(err.message);
res.status(500).json({ message: `Server error`, error: err });
}
});
router.get("/logout",(req,res) => {
res.status(200).send("<h1>You have successfully logged out</h1>");
})
module.exports = router;