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
|
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"}'
|
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;
|
module.exports = app;
|
||||||
|
|
||||||
|
process.nextTick(() => require('./mqttApp'));
|
||||||
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.set("json spaces", 2);
|
app.set("json spaces", 2);
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const app = require('../app');
|
const app = require('../app');
|
||||||
const mqttApp = require('../mqttApp');
|
|
||||||
const debug = require('debug')('proxy-api:server');
|
const debug = require('debug')('proxy-api:server');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
@ -6,7 +6,6 @@ async function getLocation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function addLocation(name, added_by, description) {
|
async function addLocation(name, added_by, description) {
|
||||||
console.log(name, added_by, description);
|
|
||||||
const location = await locationModel.create({
|
const location = await locationModel.create({
|
||||||
name: name,
|
name: name,
|
||||||
added_by: added_by,
|
added_by: added_by,
|
||||||
@ -30,7 +29,6 @@ async function updateLocation(id, name, added_by, description) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteLocation(id) {
|
async function deleteLocation(id) {
|
||||||
//delete by id
|
|
||||||
const location = await locationModel.destroy({
|
const location = await locationModel.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
@ -38,6 +36,7 @@ async function deleteLocation(id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function getLocationById(id) {
|
async function getLocationById(id) {
|
||||||
const location = await locationModel.findAll({
|
const location = await locationModel.findAll({
|
||||||
where: {
|
where: {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
const {sensorModel} = require("../database/model/sensorModel");
|
const { sensorModel } = require("../database/model/sensorModel");
|
||||||
|
|
||||||
|
|
||||||
async function getSensor() {
|
async function getSensor() {
|
||||||
const sensor = await sensorModel.findAll();
|
const sensor = await sensorModel.findAll();
|
||||||
@ -49,12 +48,12 @@ async function updateSensor(
|
|||||||
async function deleteSensor(id) {
|
async function deleteSensor(id) {
|
||||||
//delete by id
|
//delete by id
|
||||||
const sensor = await sensorModel.destroy({
|
const sensor = await sensorModel.destroy({
|
||||||
|
//cascade delete
|
||||||
|
onDelete: "cascade",
|
||||||
where: {
|
where: {
|
||||||
id: id,
|
id: id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSensorById(id) {
|
async function getSensorById(id) {
|
||||||
|
@ -25,7 +25,7 @@ async function addSensorData(id_sensor, id_location, sensordata) {
|
|||||||
locationid: id_location,
|
locationid: id_location,
|
||||||
measurement: sensordata,
|
measurement: sensordata,
|
||||||
});
|
});
|
||||||
io().emit('sensordata:new', sensorData)
|
io().emit('sensorData:new', sensorData)
|
||||||
|
|
||||||
return sensorData;
|
return sensorData;
|
||||||
}
|
}
|
||||||
|
@ -20,28 +20,6 @@ async function getUserID(userid) {
|
|||||||
return userRes;
|
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
|
//api/v0/auth/register
|
||||||
/* Registering new user
|
/* Registering new user
|
||||||
1) req.body is taken from html form or wtv
|
1) req.body is taken from html form or wtv
|
||||||
|
@ -18,8 +18,8 @@ router.use('/location', [apikeyCheck , APIlogger], require('./location.js'));
|
|||||||
//location route
|
//location route
|
||||||
router.use('/sensor', [apikeyCheck , APIlogger], require('./sensor.js'));
|
router.use('/sensor', [apikeyCheck , APIlogger], require('./sensor.js'));
|
||||||
|
|
||||||
//location route
|
//sensor data route
|
||||||
router.use('/sensor-data', [apikeyCheck, APIlogger], require('./sensorData.js'));
|
router.use('/sensor-data', [ APIlogger], require('./sensorData.js'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ router.get("/", async (req, res, next) => {
|
|||||||
//add location
|
//add location
|
||||||
router.post("/new", async (req, res, next) => {
|
router.post("/new", async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
console.log(req.body);
|
|
||||||
const { name, added_by, description } = req.body;
|
const { name, added_by, description } = req.body;
|
||||||
await addLocation(name, added_by, description);
|
await addLocation(name, added_by, description);
|
||||||
res.sendStatus(200)
|
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";
|
"use strict";
|
||||||
|
|
||||||
var router = require("express").Router();
|
var router = require("express").Router();
|
||||||
|
@ -1,41 +1,39 @@
|
|||||||
<%- include('top') %>
|
<%- include('top') %>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#sensorDataList{
|
#sensorDataList {
|
||||||
padding-top: 2.5em;
|
padding-top: 2.5em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ul id="sensorDataList">
|
<ul id="sensorDataList">
|
||||||
<li jq-repeat='sensorData'>
|
<li jq-repeat='sensorData'>
|
||||||
rowid: {{ id }}
|
rowid: {{ id }}
|
||||||
sensorId: {{ sensorid }}
|
sensorId: {{ sensorid }}
|
||||||
created: {{ createdAt }}
|
created: {{ createdAt }}
|
||||||
location: {{ locationid }}
|
location: {{ locationid }}
|
||||||
<br/ >
|
<br />
|
||||||
co: {{ measurement.co }}
|
co: {{ measurement.co }}
|
||||||
humidity: {{ measurement.humidity }}
|
humidity: {{ measurement.humidity }}
|
||||||
no2: {{ measurement.no2 }}
|
no2: {{ measurement.no2 }}
|
||||||
o3: {{ measurement.o3 }}
|
o3: {{ measurement.o3 }}
|
||||||
psi: {{ measurement.psi }}
|
psi: {{ measurement.psi }}
|
||||||
so2: {{ measurement.so2 }}
|
so2: {{ measurement.so2 }}
|
||||||
temperature: {{ measurement.temperature }}
|
temperature: {{ measurement.temperature }}
|
||||||
windspeed: {{ measurement.windspeed }}
|
windspeed: {{ measurement.windspeed }}
|
||||||
<hr />
|
<hr />
|
||||||
</li>
|
</li>
|
||||||
<li jq-repeat-defualt='sensorData'>
|
<li jq-repeat-defualt='sensorData'>
|
||||||
Loading...
|
Loading...
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(async function(){
|
$(document).ready(async function () {
|
||||||
$.scope.sensorData.push(...await app.api.get('sensor-data/data?order=DESC&limit=40'));
|
app.api.get('sensor-data/data?order=DESC&limit=40', function(error, data){
|
||||||
|
$.scope.sensorData.push(...data);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
app.socket.on('sensordata:new', function(data){
|
</script>
|
||||||
$.scope.sensorData.unshift(data);
|
<%- include('bot') %>
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<%- include('bot') %>
|
|
@ -128,6 +128,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
x
Reference in New Issue
Block a user