This commit is contained in:
newtbot
2024-01-24 16:01:30 +08:00
parent d0aeab286a
commit 7403f66c8a
12 changed files with 44 additions and 114 deletions

View File

@ -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: {

View File

@ -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,
};
};

View File

@ -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;
}

View File

@ -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