-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
76 lines (60 loc) · 3.25 KB
/
server.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
require("dotenv").config({ path: __dirname + "/.env" });
const InitializationService = require("./services/initialization.service");
InitializationService.initialize();
const { validateSignup, validateLogin, validateUseRefreshToken, validateDeleteRefreshToken } = require("./utils/error_handling");
const user = require("./controllers/user");
const auth = require("./controllers/auth");
const alarmMetrics = require("./controllers/metrics/alarm");
const responseMetrics = require("./controllers/metrics/response");
const arrivalMetrics = require("./controllers/metrics/arrival");
const treatementMetrics = require("./controllers/metrics/treatment");
const notification = require("./controllers/notification");
const help_request = require("./controllers/help_request")
var express = require("express");
var bodyParser = require("body-parser");
var logger = require("morgan")
let middleware = require("./middleware");
const port = process.env.PORT || 3000;
const app = express()
app.use(express.static(__dirname + "/../public"));
app.use(bodyParser.json());
app.use(logger("dev"))
app.use(express.static("public"));
app.use(bodyParser.urlencoded({
extended: true
}));
app.get("/", (req, res) => res.send("Server is up"))
app.post("/signup", validateSignup(), auth.signup);
app.post("/login", validateLogin(), auth.login);
app.post("/refresh-token", validateUseRefreshToken(), auth.useRefreshToken);
app.post("/users/:id/responders", middleware.checkToken, user.addResponders);
app.post("/users/:id/notification-token", user.addPushToken);
app.put("/users/:id/location", middleware.checkToken, user.updateLocation);
app.get("/users/:id/location", middleware.checkToken, user.getLocation);
app.post("/users/:id/status", middleware.checkToken, user.toggleOnlineAndNaloxoneAvailabilityStatus);
app.get("/users/search", middleware.checkToken, user.searchUsers);
app.get("/users/:id", middleware.checkToken, user.userInfo);
app.get("/users/:id/responders", middleware.checkToken, user.getResponders);
app.get("/users/:id/responders/count", middleware.checkToken, user.getResponderCount);
app.get("/users/:id/responding-to", middleware.checkToken, user.respondingTo);
app.delete("/users/:id/responders", middleware.checkToken, user.deleteResponders);
// Help requests
app.post("/help-requests/", middleware.checkToken, help_request.addHelpRequest);
app.get("/help-requests/:id", middleware.checkToken, help_request.getHelpRequest)
app.put("/help-requests/:id", middleware.checkToken, help_request.putHelpRequest);
app.get("/help-requests/:id/responders/count", middleware.checkToken, help_request.getHelpRequestResponderCount)
// Alarm metrics
app.post("/metrics/alarm", middleware.checkToken, alarmMetrics.alarmStart);
app.put("/metrics/alarm/:alarmID", middleware.checkToken, alarmMetrics.alarmUpdate);
// Response metrics
app.post("/metrics/response", middleware.checkToken, responseMetrics.recordResponse);
// Arrival metrics
app.post("/metrics/arrival", middleware.checkToken, arrivalMetrics.responderArrival);
// Treatement metrics
app.post("/metrics/treatment", middleware.checkToken, treatementMetrics.recordTreatment);
// FOR TESTING ONLY
app.get("/test-notif", notification.testSendNotification);
app.listen(port, function () {
console.log(`Server is running on port ${port}`);
});
export default app;