Add routes to get location and sensor by name
Added viewdata using chart.js
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
const {locationModel} = require("../database/model/locationModel");
|
||||
const {Op} = require("sequelize");
|
||||
|
||||
async function getLocation() {
|
||||
const location = await locationModel.findAll();
|
||||
@ -35,7 +36,32 @@ async function deleteLocation(id) {
|
||||
},
|
||||
});
|
||||
}
|
||||
/*
|
||||
const { Op } = require("sequelize");
|
||||
|
||||
var options = {
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{ 'subject': { [Op.like]: '%' + query + '%' } },
|
||||
{ '$Comment.body$': { [Op.like]: '%' + query + '%' } }
|
||||
]
|
||||
},
|
||||
include: [{ model: Comment }]
|
||||
};
|
||||
*/
|
||||
|
||||
async function getLocationByName(name) {
|
||||
const location = await locationModel.findAll({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{name: {[Op.like]: "%" + name + "%"}},
|
||||
{added_by: {[Op.like]: "%" + name + "%"}},
|
||||
{description: {[Op.like]: "%" + name + "%"}},
|
||||
],
|
||||
},
|
||||
});
|
||||
return location;
|
||||
}
|
||||
|
||||
async function getLocationById(id) {
|
||||
const location = await locationModel.findAll({
|
||||
@ -51,5 +77,6 @@ module.exports = {
|
||||
addLocation,
|
||||
updateLocation,
|
||||
deleteLocation,
|
||||
getLocationByName,
|
||||
getLocationById,
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
const { sensorModel } = require("../database/model/sensorModel");
|
||||
const {Op} = require("sequelize");
|
||||
|
||||
async function getSensor() {
|
||||
const sensor = await sensorModel.findAll();
|
||||
@ -55,6 +56,33 @@ async function deleteSensor(id) {
|
||||
},
|
||||
});
|
||||
}
|
||||
/*
|
||||
async function getLocationByName(name) {
|
||||
const location = await locationModel.findAll({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{name: {[Op.like]: "%" + name + "%"}},
|
||||
{added_by: {[Op.like]: "%" + name + "%"}},
|
||||
{description: {[Op.like]: "%" + name + "%"}},
|
||||
],
|
||||
},
|
||||
});
|
||||
return location;
|
||||
}
|
||||
*/
|
||||
async function getSensorByName(name) {
|
||||
const sensor = await sensorModel.findAll({
|
||||
where: {
|
||||
[Op.or]: [
|
||||
{name: {[Op.like]: "%" + name + "%"}},
|
||||
{added_by: {[Op.like]: "%" + name + "%"}},
|
||||
{mac_address: {[Op.like]: "%" + name + "%"}},
|
||||
{description: {[Op.like]: "%" + name + "%"}},
|
||||
],
|
||||
},
|
||||
});
|
||||
return sensor;
|
||||
}
|
||||
|
||||
async function getSensorById(id) {
|
||||
const sensor = await sensorModel.findAll({
|
||||
@ -70,5 +98,6 @@ module.exports = {
|
||||
addSensor,
|
||||
updateSensor,
|
||||
deleteSensor,
|
||||
getSensorByName,
|
||||
getSensorById,
|
||||
};
|
||||
|
Reference in New Issue
Block a user