diff --git a/api.MD b/api.MD index de38469..2f590e4 100644 --- a/api.MD +++ b/api.MD @@ -169,8 +169,6 @@ http://localhost/api/v0/sensor-data/filter?windspeed=highest&limit=1 http://localhost/api/v0/sensor-data/data?week=1&sensorid=1&locationid=1&page=2&pagesize=10 - - curl localhost/api/v0/user/register -H "Content-Type: application/json" -X POST -d '{"username": "testuser123", "password": "thisisthesystemuserpasswordnoob", "email": "testuser123@ecosaver.com", "address": "Nanyang Polytechnic 180 Ang Mo Kio Avenue 8 Singapore 569830", "phone": "12345678"}' diff --git a/consumerWebsite/app.js b/consumerWebsite/app.js index dc3c301..ce7fee1 100644 --- a/consumerWebsite/app.js +++ b/consumerWebsite/app.js @@ -7,6 +7,8 @@ const ejs = require("ejs"); module.exports = app; +process.nextTick(() => require('./mqttApp')); + app.use(express.json()); app.set("json spaces", 2); diff --git a/consumerWebsite/bin/www b/consumerWebsite/bin/www index ae5fa70..dad62b9 100644 --- a/consumerWebsite/bin/www +++ b/consumerWebsite/bin/www @@ -5,7 +5,6 @@ */ const app = require('../app'); -const mqttApp = require('../mqttApp'); const debug = require('debug')('proxy-api:server'); const http = require('http'); const path = require('path'); diff --git a/consumerWebsite/functions/location.js b/consumerWebsite/functions/location.js index 97fc0c4..4b5baf2 100644 --- a/consumerWebsite/functions/location.js +++ b/consumerWebsite/functions/location.js @@ -6,7 +6,6 @@ async function getLocation() { } async function addLocation(name, added_by, description) { - console.log(name, added_by, description); const location = await locationModel.create({ name: name, added_by: added_by, @@ -30,7 +29,6 @@ async function updateLocation(id, name, added_by, description) { } async function deleteLocation(id) { - //delete by id const location = await locationModel.destroy({ where: { id: id, @@ -38,6 +36,7 @@ async function deleteLocation(id) { }); } + async function getLocationById(id) { const location = await locationModel.findAll({ where: { diff --git a/consumerWebsite/functions/sensor.js b/consumerWebsite/functions/sensor.js index 66994eb..a72512b 100644 --- a/consumerWebsite/functions/sensor.js +++ b/consumerWebsite/functions/sensor.js @@ -1,5 +1,4 @@ -const {sensorModel} = require("../database/model/sensorModel"); - +const { sensorModel } = require("../database/model/sensorModel"); async function getSensor() { const sensor = await sensorModel.findAll(); @@ -49,12 +48,12 @@ async function updateSensor( async function deleteSensor(id) { //delete by id const sensor = await sensorModel.destroy({ + //cascade delete + onDelete: "cascade", where: { id: id, }, }); - - console.error(error); } async function getSensorById(id) { @@ -72,4 +71,4 @@ module.exports = { updateSensor, deleteSensor, getSensorById, -}; \ No newline at end of file +}; diff --git a/consumerWebsite/functions/sensorData.js b/consumerWebsite/functions/sensorData.js index f913ce0..28cf3a0 100644 --- a/consumerWebsite/functions/sensorData.js +++ b/consumerWebsite/functions/sensorData.js @@ -25,7 +25,7 @@ async function addSensorData(id_sensor, id_location, sensordata) { locationid: id_location, measurement: sensordata, }); - io().emit('sensordata:new', sensorData) + io().emit('sensorData:new', sensorData) return sensorData; } diff --git a/consumerWebsite/functions/user.js b/consumerWebsite/functions/user.js index 9cfb6e0..ee5cdb0 100644 --- a/consumerWebsite/functions/user.js +++ b/consumerWebsite/functions/user.js @@ -20,28 +20,6 @@ async function getUserID(userid) { return userRes; } -//register -//api/v0/auth/register -async function addUser(user) { - //hash password - let hashed = await hash(user.password); - - const addRes = await userModel.create({ - firstname: user.firstname, - lastname: user.lastname, - username: user.username, - password: hashed, - email: user.email, - address: user.address, - phone: user.phone, - }); - if (addRes) { - return true; - } else { - return false; - } -} - //api/v0/auth/register /* Registering new user 1) req.body is taken from html form or wtv diff --git a/consumerWebsite/routes/api_routes.js b/consumerWebsite/routes/api_routes.js index 080c427..ebd16ed 100644 --- a/consumerWebsite/routes/api_routes.js +++ b/consumerWebsite/routes/api_routes.js @@ -18,8 +18,8 @@ router.use('/location', [apikeyCheck , APIlogger], require('./location.js')); //location route router.use('/sensor', [apikeyCheck , APIlogger], require('./sensor.js')); -//location route -router.use('/sensor-data', [apikeyCheck, APIlogger], require('./sensorData.js')); +//sensor data route +router.use('/sensor-data', [ APIlogger], require('./sensorData.js')); module.exports = router; diff --git a/consumerWebsite/routes/location.js b/consumerWebsite/routes/location.js index 6551e5e..cc7ce2b 100644 --- a/consumerWebsite/routes/location.js +++ b/consumerWebsite/routes/location.js @@ -25,7 +25,6 @@ router.get("/", async (req, res, next) => { //add location router.post("/new", async (req, res, next) => { try { - console.log(req.body); const { name, added_by, description } = req.body; await addLocation(name, added_by, description); res.sendStatus(200) diff --git a/consumerWebsite/routes/render.js b/consumerWebsite/routes/render.js index 8e6f74b..8c98d9f 100644 --- a/consumerWebsite/routes/render.js +++ b/consumerWebsite/routes/render.js @@ -1,42 +1,3 @@ -/* -'use strict'; - -var router = require('express').Router(); -const conf = require('../conf') - -const values ={ - title: conf.environment !== 'production' ? `` : '' -} - -router.get('/', async function(req, res, next) { - res.render('runner', {...values}); -}); - - -router.get('/topics', function(req, res, next) { - res.render('topics', {...values}); -}); - -router.get('/chat', function(req, res, next) { - res.render('chat', {...values}); -}); - -router.get('/login*', function(req, res, next) { - res.render('login', {redirect: req.query.redirect, ...values}); -}); - -router.get('/runner', function(req, res, next) { - res.render('runner', {...values}); -}); - -router.get('/worker', function(req, res, next) { - res.render('worker', {...values}); -}); - -module.exports = router; - -*/ - "use strict"; var router = require("express").Router(); diff --git a/consumerWebsite/views/sensor-data.ejs b/consumerWebsite/views/sensor-data.ejs index 4013dc0..c46510b 100644 --- a/consumerWebsite/views/sensor-data.ejs +++ b/consumerWebsite/views/sensor-data.ejs @@ -1,41 +1,39 @@ <%- include('top') %> - + - + - -<%- include('bot') %> \ No newline at end of file + + <%- include('bot') %> \ No newline at end of file diff --git a/consumerWebsite/views/top.ejs b/consumerWebsite/views/top.ejs index 276d928..df0b5a5 100644 --- a/consumerWebsite/views/top.ejs +++ b/consumerWebsite/views/top.ejs @@ -128,6 +128,3 @@ - - - \ No newline at end of file