api route wip

This commit is contained in:
newtbot
2023-12-30 01:02:09 +08:00
parent 3913d0d2f7
commit 73b43adb3a
12 changed files with 239 additions and 42 deletions

View File

@ -0,0 +1,39 @@
const { sequelize } = require("../../Database/mySql.js");
const { IoTModel } = require("../../Database/model/IoTModel.js");
async function getallData() {
try {
sequelize.sync();
const allData = await IoTModel.findAll({
attributes: ['id', 'psiData', 'humidityData', 'o3Data', 'no2Data', 'so2Data', 'coData', 'temperatureData', 'windspeedData', 'currentTime', 'regionData' , 'createdAt' , 'updatedAt'],
});
return allData;
}
catch(error) {
console.error(error);
return null;
}
}
async function getLatestData() {
try {
sequelize.sync();
const latestData = await IoTModel.findAll({
limit: 1,
order: [['createdAt', 'DESC']]
});
return latestData;
}
catch (error) {
console.error(error);
return null;
}
}
module.exports = { getallData , getLatestData };