updated readme and usability

This commit is contained in:
Daniel Ledda
2021-11-23 20:31:53 +01:00
parent 514785c63d
commit 04af7ee999
5 changed files with 64 additions and 12 deletions

View File

@@ -10,11 +10,19 @@ export async function establishDatabaseConnection() {
host: process.env.MYSQL_ADDRESS,
user: process.env.MYSQL_USERNAME,
password: process.env.MYSQL_PW,
database: "climate",
connectTimeout: 30000,
});
await dbConnection.query("CREATE DATABASE IF NOT EXISTS `climate`;");
dbConnection.changeUser({database: "climate"});
await dbConnection.query(`CREATE TABLE IF NOT EXISTS \`snapshots\` (
\`id\` INT AUTO_INCREMENT PRIMARY KEY,
\`temp\` INT NOT NULL,
\`humidity\` INT NOT NULL,
\`co2\` INT NOT NULL,
\`time\` DATETIME NOT NULL);`
);
} catch (e) {
throw new Error(`Couldn't establish a connection with the database: ${e.message}`);
throw new Error(`Error setting up the database: ${e.message}`);
}
return dbConnection;
}

View File

@@ -6,14 +6,12 @@ import newByteSeriesRouter from "./byteSeriesRouter";
export function newMainRouter(collections: CollectionRegistry) {
const router = express.Router();
const snapshotRouter = newSnapshotRouter(collections);
const byteSeriesRouter = newByteSeriesRouter(collections);
router.get("/dashboard", (req, res) => {
res.render("index.ejs", { rootUrl: req.app.locals.rootUrl });
});
router.use("/api/snapshots", snapshotRouter);
router.use("/api/timeseries", byteSeriesRouter);
router.use("/api/snapshots", newSnapshotRouter(collections));
router.use("/api/timeseries", newByteSeriesRouter(collections));
router.use(topLevelErrorHandler);
return router;