-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
106 lines (92 loc) · 4.16 KB
/
Copy pathapp.js
File metadata and controls
106 lines (92 loc) · 4.16 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
// noinspection JSCheckFunctionSignatures,JSUnresolvedFunction
const express = require('express');
const app = express();
const db = require('./database/db-config');
const loggedIn = require('./controllers/loggedIn');
const getGeneralPost = require('./sql-functions/getGeneralPost');
const getAdminPost = require('./sql-functions/getAdminPost');
const addPatient = require('./sql-functions/add-patient')
const getPatientCount = require('./sql-functions/getPatientCount')
const getPillStockCount = require('./sql-functions/getPillStockCount')
const getPillAssignedCount = require('./sql-functions/getPillAssignedCount')
const getPillLowStock = require('./sql-functions/getPillLowStock')
const getHighAlertCount = require('./sql-functions/getHighAlertCount')
const getHighAlertList = require('./sql-functions/getHighAlertList')
const getTable = require('./sql-functions/getTable')
const getTablePill = require('./sql-functions/getTablePill')
const getUsers = require('./sql-functions/getUsers')
const addPill = require('./sql-functions/add-pill')
const addPost = require('./sql-functions/addPost')
const cookie = require('cookie-parser');
const path = require("path");
const _ = require('lodash');
const port = 3000;
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({ extended: true }));
app.use("/auth", require("./controllers/auth"));
app.use("/update", require("./sql-functions/update"));
app.set('view engine', 'ejs');
app.use(cookie());
app.use(express.json());
db.connect((err) => {
if (err) {
console.log(err);
console.log('Error connecting to database');
} else {
console.log('Connected to MySQL as ID: ' + db.threadId);
}
});
app.get('/', [loggedIn, getPatientCount, getPillStockCount, getHighAlertCount, getPillAssignedCount, getGeneralPost, getAdminPost, getUsers], (req, res) => {
if (req.user) {
res.render('index', { user: req.user, status: 'loggedIN', noPatients: req.patientCount, noPills: req.pillStockCount, users: req.usersToRender ,noHighAlert: req.highAlertCount, noPillsAssigned: req.pillAssignedCount, posts: req.postsToRender, adminPosts: req.adminPostsToRender });
} else {
res.render('index', { user: "not logged in", status: 'no' });
}
});
app.get('/patient', [loggedIn, getPatientCount, getPillStockCount, getHighAlertCount, getHighAlertList, getTable], (req, res) => {
if (req.user) {
res.render('patient', { user: req.user, status: 'loggedIN', noPills: req.pillStockCount, noPatients: req.patientCount, noHighAlert: req.highAlertCount , patients: req.tableToRender, highAlertList: req.highAlertList });
} else {
res.redirect('/')
}
});
app.get('/pill', [loggedIn, getPillStockCount, getHighAlertList, getTablePill, getPillAssignedCount, getPillLowStock, getTable], (req, res) => {
if (req.user) {
res.render('pill', { user: req.user, status: 'loggedIN', noPills: req.pillStockCount, noPillsAssigned: req.pillAssignedCount , patients:req.tableToRender, pills: req.pillTableToRender, pillsLow: req.pillLowStock , highAlertList: req.highAlertList });
} else {
res.redirect('/')
}
});
app.get('/post/:postName', [loggedIn, getGeneralPost], (req, res) => {
if (req.user) {
res.render('post', { user: req.user, status: 'loggedIN', postTitle: req.postTitle, postBody: req.postBody });
} else {
res.redirect('/')
}
});
app.post('/addpatient', addPatient);
app.post('/addpill', addPill);
app.post('/addpost', addPost);
app.get('/test', loggedIn, (req, res) => {
if (req.user) {
res.render('test', { user: req.user, status: 'loggedIN' });
} else {
res.render('test', { user: "not logged in", status: 'no' });
}
});
app.get('/profile', loggedIn, (req, res) => {
if (req.user) {
res.render('profile', { user: req.user, status: 'loggedIN' });
} else {
res.render('index', { user: "not logged in", status: 'no' });
}
});
app.get('/register', (req, res) => {
res.sendFile(__dirname + '/public/register.html');
});
app.get('/login', (req, res) => {
res.sendFile(__dirname + '/public/login.html');
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});