Adjust all functions to use factored out database definition

This commit is contained in:
JayWll 2020-04-11 13:07:57 -06:00
parent b5b49c5424
commit 0711674a79

View File

@ -15,7 +15,7 @@ app.get('/newreading', (req, res) => {
// Filter out requests that don't include the secret key, or don't contain the required data // Filter out requests that don't include the secret key, or don't contain the required data
if (req.query.s != process.env.SECRET || !RegExp('^\\d*$').test(req.query.v)) return res.status(400).send('Bad Request').end(); if (req.query.s != process.env.SECRET || !RegExp('^\\d*$').test(req.query.v)) return res.status(400).send('Bad Request').end();
Readings.create({ timestamp: new Date(), reading: req.query.v }); db.Readings.create({ timestamp: new Date(), reading: req.query.v });
res.status(200).send('Reading received: ' + req.query.v).end(); res.status(200).send('Reading received: ' + req.query.v).end();
}); });
@ -50,7 +50,7 @@ app.get('/exportall', (req, res) => {
return res.status(401).send('Authorization header not found').end(); return res.status(401).send('Authorization header not found').end();
} }
Readings.findAll().then((result) => { db.Readings.findAll().then((result) => {
res.status(200).send(result).end(); res.status(200).send(result).end();
}) })
}) })
@ -67,7 +67,7 @@ app.get('/cleanup', (req, res) => {
before.setMinutes(0); before.setMinutes(0);
before.setSeconds(0); before.setSeconds(0);
Readings.destroy({ db.Readings.destroy({
where: { where: {
timestamp: { timestamp: {
[db.Op.lt]: before [db.Op.lt]: before
@ -81,6 +81,5 @@ app.get('/cleanup', (req, res) => {
// listen for requests :) // listen for requests :)
const listener = app.listen(process.env.PORT || 4200, function() { const listener = app.listen(process.env.PORT || 4200, function() {
console.log(process.env.DB_USER)
console.log("Your app is listening on port " + listener.address().port); console.log("Your app is listening on port " + listener.address().port);
}); });