WIP
This commit is contained in:
@ -23,4 +23,91 @@ log_type all
|
||||
log_facility 5
|
||||
log_dest file /var/log/mosquitto/mosquitto.log
|
||||
|
||||
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-18-04
|
||||
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-ubuntu-18-04
|
||||
|
||||
|
||||
let ormQuery = {};
|
||||
let whereClause = {};
|
||||
//let whereNest = {};
|
||||
//let whereDate = {};
|
||||
|
||||
buildFuncs = {
|
||||
month: function(query){
|
||||
const validMonths = [
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
];
|
||||
if (validMonths.includes(query.month)) {
|
||||
whereClause = {
|
||||
where: sequelize.where(
|
||||
sequelize.fn("MONTH", sequelize.col("createdAt")),
|
||||
query.month
|
||||
),
|
||||
};
|
||||
} else {
|
||||
query.month = getMonthFromString(query.month);
|
||||
whereClause = {
|
||||
where: sequelize.where(
|
||||
sequelize.fn("MONTH", sequelize.col("createdAt")),
|
||||
query.month
|
||||
),
|
||||
};
|
||||
}
|
||||
},
|
||||
week: function(query){
|
||||
whereClause.week = sequelize.where(
|
||||
sequelize.fn("WEEK", sequelize.col("createdAt")),
|
||||
query.week
|
||||
);
|
||||
},
|
||||
sensorid: function (query){
|
||||
whereClause.sensorid = sequelize.where(
|
||||
sequelize.col("sensorid"),
|
||||
query.sensorid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function getData(queryString)
|
||||
for(let query in queryString){
|
||||
if(buildFuncs[query]); buildFuncs[query](queryString)
|
||||
|
||||
if (!whereClause) {
|
||||
return await sensorDataModel.findAll(ormQuery);
|
||||
} else if (whereClause) {
|
||||
console.log(whereClause);
|
||||
//console.log(whereNest);
|
||||
//console.log(whereDate);
|
||||
console.log(query);
|
||||
console.log(ormQuery);
|
||||
|
||||
return await sensorDataModel.findAll({
|
||||
//limit default value if query.limit is undefined or not provided
|
||||
limit: query.limit,
|
||||
//The operators Op.and, Op.or and Op.not can be used to create arbitrarily complex nested logical comparisons.
|
||||
//https://sequelize.org/docs/v6/core-concepts/model-querying-basics/#examples-with-opand-and-opor
|
||||
where: {
|
||||
//[Op.and]: [whereNest, whereClause],
|
||||
[Op.and]: [whereClause],
|
||||
createdAt: {
|
||||
//https://stackoverflow.com/questions/43115151/sequelize-query-to-find-all-records-that-falls-in-between-date-range
|
||||
[Op.between]: [whereClause.startdate, whereClause.enddate],
|
||||
},
|
||||
},
|
||||
|
||||
//only use where clause to lookup based on condition that i put into whereClause
|
||||
...ormQuery,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user