more fix
This commit is contained in:
parent
d0aeab286a
commit
7403f66c8a
2
api.MD
2
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"}'
|
||||
|
||||
|
||||
|
@ -7,6 +7,8 @@ const ejs = require("ejs");
|
||||
|
||||
module.exports = app;
|
||||
|
||||
process.nextTick(() => require('./mqttApp'));
|
||||
|
||||
app.use(express.json());
|
||||
app.set("json spaces", 2);
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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: {
|
||||
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -1,42 +1,3 @@
|
||||
/*
|
||||
'use strict';
|
||||
|
||||
var router = require('express').Router();
|
||||
const conf = require('../conf')
|
||||
|
||||
const values ={
|
||||
title: conf.environment !== 'production' ? `<i class="fa-brands fa-dev"></i>` : ''
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -1,41 +1,39 @@
|
||||
<%- include('top') %>
|
||||
|
||||
<style>
|
||||
#sensorDataList{
|
||||
padding-top: 2.5em;
|
||||
}
|
||||
</style>
|
||||
<style>
|
||||
#sensorDataList {
|
||||
padding-top: 2.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<ul id="sensorDataList">
|
||||
<li jq-repeat='sensorData'>
|
||||
rowid: {{ id }}
|
||||
sensorId: {{ sensorid }}
|
||||
created: {{ createdAt }}
|
||||
location: {{ locationid }}
|
||||
<br/ >
|
||||
co: {{ measurement.co }}
|
||||
humidity: {{ measurement.humidity }}
|
||||
no2: {{ measurement.no2 }}
|
||||
o3: {{ measurement.o3 }}
|
||||
psi: {{ measurement.psi }}
|
||||
so2: {{ measurement.so2 }}
|
||||
temperature: {{ measurement.temperature }}
|
||||
windspeed: {{ measurement.windspeed }}
|
||||
<hr />
|
||||
</li>
|
||||
<li jq-repeat-defualt='sensorData'>
|
||||
Loading...
|
||||
</li>
|
||||
</ul>
|
||||
<ul id="sensorDataList">
|
||||
<li jq-repeat='sensorData'>
|
||||
rowid: {{ id }}
|
||||
sensorId: {{ sensorid }}
|
||||
created: {{ createdAt }}
|
||||
location: {{ locationid }}
|
||||
<br />
|
||||
co: {{ measurement.co }}
|
||||
humidity: {{ measurement.humidity }}
|
||||
no2: {{ measurement.no2 }}
|
||||
o3: {{ measurement.o3 }}
|
||||
psi: {{ measurement.psi }}
|
||||
so2: {{ measurement.so2 }}
|
||||
temperature: {{ measurement.temperature }}
|
||||
windspeed: {{ measurement.windspeed }}
|
||||
<hr />
|
||||
</li>
|
||||
<li jq-repeat-defualt='sensorData'>
|
||||
Loading...
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(async function(){
|
||||
$.scope.sensorData.push(...await app.api.get('sensor-data/data?order=DESC&limit=40'));
|
||||
<script type="text/javascript">
|
||||
$(document).ready(async function () {
|
||||
app.api.get('sensor-data/data?order=DESC&limit=40', function(error, data){
|
||||
$.scope.sensorData.push(...data);
|
||||
})
|
||||
})
|
||||
|
||||
app.socket.on('sensordata:new', function(data){
|
||||
$.scope.sensorData.unshift(data);
|
||||
});
|
||||
})
|
||||
|
||||
</script>
|
||||
<%- include('bot') %>
|
||||
</script>
|
||||
<%- include('bot') %>
|
@ -128,6 +128,3 @@
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user