From 49371e546f6a493cf844b207920969900134f79b Mon Sep 17 00:00:00 2001 From: BIG2EYEZ Date: Mon, 15 Jan 2024 16:35:09 +0800 Subject: [PATCH] cleanup --- Sean/modules/mysql.js | 10 +-- Sean/server.js | 31 +------- Sean/views/home.ejs | 175 +----------------------------------------- 3 files changed, 7 insertions(+), 209 deletions(-) diff --git a/Sean/modules/mysql.js b/Sean/modules/mysql.js index 4ae5252..c0572d8 100644 --- a/Sean/modules/mysql.js +++ b/Sean/modules/mysql.js @@ -40,14 +40,8 @@ const connection = mysql.createConnection({ timezone: "Z", // Set the timezone to UTC }); - const connection2 = mysql.createConnection({ - host: process.env.host, - user: process.env.DB_USER, - password: process.env.DB_PASS, - database: "eco_saver", - timezone: "Z", // Set the timezone to UTC - }); -module.exports = { connection,connection2 }; + +module.exports = { connection, }; diff --git a/Sean/server.js b/Sean/server.js index 5d281ec..91604e3 100644 --- a/Sean/server.js +++ b/Sean/server.js @@ -11,7 +11,7 @@ const validator = require('validator'); const { transporter } = require("./modules/nodeMailer"); const { connection } = require("./modules/mysql"); -const { connection2 } = require("./modules/mysql"); + const app = express(); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); @@ -302,39 +302,14 @@ app.use(setCSRFToken); }); - - - - app.get("/home", isAuthenticated, (req, res) => { - - // Retrieve the last 10 sensor data records from the sensordata table - const sensorDataQuery = - "SELECT locationid, measurement, createdAt FROM sensordata ORDER BY createdAt DESC LIMIT 10"; - - connection2.query(sensorDataQuery, (error, sensorDataResults) => { - if (error) { - console.error("Error executing sensor data query:", error); - res.status(500).send("Internal Server Error"); - return; - } // Render the home page with sensor data res.render("home", { username: req.session.username, - sensorData: sensorDataResults, }); }); - }); - app.get('/api/locations', (req, res) => { - connection2.query('SELECT `id`, `name` FROM `locations`', (error, results) => { - if (error) { - console.error('Error fetching locations:', error); - res.status(500).json({ error: 'Internal Server Error' }); - return; - } - res.json(results); - }); -}); + + app.get("/inusers", isAuthenticated, (req, res) => { // Fetch all user data from the database diff --git a/Sean/views/home.ejs b/Sean/views/home.ejs index 41251db..929ea47 100644 --- a/Sean/views/home.ejs +++ b/Sean/views/home.ejs @@ -53,35 +53,11 @@ text-align: center; } - table { - border-collapse: collapse; - width: 80%; - margin: 20px auto; - font-size: 16px; - } - - th, td { - border: 1px solid #dddddd; - text-align: left; - padding: 12px; - } - - th { - background-color: #f2f2f2; - } - - tr:hover { - background-color: #f5f5f5; - } - - td { - white-space: nowrap; - } - +