Fix ordering of items before responding to request

This commit is contained in:
Skylar Grant 2023-01-22 23:09:32 -05:00
parent 2bb376868d
commit 1e1d3488c2

View File

@ -29,32 +29,41 @@ app.set('view engine', 'html');
// A normal load of the root page // A normal load of the root page
app.get('/', (req, res) => { app.get('/', (req, res) => {
if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${JSON.stringify(config)}`); // if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: ${JSON.stringify(config)}`);
res.render('index', { config: JSON.stringify(config) }); res.render('index', { config: JSON.stringify(config) });
}); });
// A POST form submission to the root page // A POST form submission to the root page
app.post('/', (req, res) => { app.post('/', (req, response) => {
res.render('index', { config: JSON.stringify(config) });
if (req.body.start != undefined) { if (req.body.start != undefined) {
fn.commands.startup(); fn.commands.startup();
response.render('index', { config: JSON.stringify(config) });
return;
} }
if (req.body.shutdown != undefined) { if (req.body.shutdown != undefined) {
fn.commands.shutdown(); fn.commands.shutdown();
response.render('index', { config: JSON.stringify(config) });
return;
} }
if (req.body.reload != undefined) { if (req.body.reload != undefined) {
const updateAugerOffIntervalQuery = `UPDATE intervals SET value = '${2000 - req.body.feedRate}' WHERE key = 'auger_off'`; const updateAugerOffIntervalQuery = `UPDATE intervals SET value = '${2000 - req.body.feedRate}' WHERE key = 'auger_off'`;
const updateAugerOnIntervalQuery = `UPDATE intervals SET value = '${req.body.feedRate}' WHERE key = 'auger_on'`; const updateAugerOnIntervalQuery = `UPDATE intervals SET value = '${req.body.feedRate}' WHERE key = 'auger_on'`;
dbfn.run(updateAugerOffIntervalQuery).then(res => { dbfn.run(updateAugerOffIntervalQuery).then(res => {
if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger off interval updated: ${res.data.changes}`); if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger off interval updated: ${res.data.changes}`);
}).catch(err => console.log(`E: ${err}`)); dbfn.run(updateAugerOnIntervalQuery).then(res => {
if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger on interval updated: ${res.data.changes}`);
dbfn.run(updateAugerOnIntervalQuery).then(res => { fn.commands.refreshConfig().then(res => {
if (process.env.DEBUG) console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Auger on interval updated: ${res.data.changes}`); config = res.config;
response.render('index', { config: JSON.stringify(config) });
return;
});
}).catch(err => console.log(`E: ${err}`));
}).catch(err => console.log(`E: ${err}`)); }).catch(err => console.log(`E: ${err}`));
} }
if (req.body.quit != undefined) { if (req.body.quit != undefined) {
fn.commands.quit(); fn.commands.quit();
response.render('index', { config: JSON.stringify(config) });
return;
} }
}); });