Added route and DB scaffolds

This commit is contained in:
Alex Holliday committed 2024-05-27 13:51:51 -07:00
1 parent b945c73c87
commit 1e398d9153
4 files changed
+137

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
var jwt = require("jsonwebtoken");
const SERVICE_NAME = "check";
const createCheck = (req, res, next) => {
try {
req.db.createCheck(req, res);
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
const getChecks = (req, res, next) => {
try {
req.db.getChecks(req, res);
// Return all checks for a monitor
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
const deleteChecks = (req, res, next) => {
try {
req.db.deleteChecks(req, res);
// Delete all checks for a monitor
} catch (error) {
error.service = SERVICE_NAME;
next(error);
}
};
module.exports = {
createCheck,
getChecks,
deleteChecks,
};
+74
View File
@@ -16,6 +16,10 @@ const connect = async () => {
}
};
//****************************************
// Users
//****************************************
/**
* Insert a User
* @async
@@ -55,6 +59,10 @@ const getUserByEmail = async (req, res) => {
}
};
//****************************************
// Monitors
//****************************************
/**
* Get all monitors
* @async
@@ -169,6 +177,69 @@ const editMonitor = async (req, res) => {
}
};
//****************************************
// Checks
//****************************************
/**
* Create a check for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const createCheck = async (req, res) => {
try {
// Create check with monitor id
res
.status(200)
.json({ success: true, msg: "Create check", data: req.params.monitorId });
} catch (error) {
throw error;
}
};
/**
* Get all checks for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const getChecks = async (req, res) => {
try {
// TODO get all checks for a monitor from DB
res
.status(200)
.json({ success: true, msg: "Get checks", data: req.params.monitorId });
} catch (error) {
throw error;
}
};
/**
* Delete all checks for a monitor
* @async
* @param {Express.Request} req
* @param {Express.Response} res
* @throws {Error}
*/
const deleteChecks = async (req, res) => {
try {
// TODO Delete all checks for a monitor
res.status(200).json({
success: true,
msg: "Deleted checks",
data: req.params.monitorId,
});
} catch (error) {
throw error;
}
};
module.exports = {
connect,
insertUser,
@@ -179,4 +250,7 @@ module.exports = {
createMonitor,
deleteMonitor,
editMonitor,
createCheck,
getChecks,
deleteChecks,
};
+2
View File
@@ -3,6 +3,7 @@ const helmet = require("helmet");
const cors = require("cors");
const authRouter = require("./routes/authRoute");
const monitorRouter = require("./routes/monitorRoute");
const checkRouter = require("./routes/checkRoute");
const { connectDbAndRunServer } = require("./configs/db");
require("dotenv").config();
const logger = require("./utils/logger");
@@ -62,6 +63,7 @@ app.use((req, res, next) => {
//routes
app.use("/api/v1/auth", authRouter);
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
app.use("/api/v1/checks", verifyJWT, checkRouter);
/**
* Error handler middleware
+24
View File
@@ -0,0 +1,24 @@
const router = require("express").Router();
const checkController = require("../controllers/checkController");
const { verifyOwnership } = require("../middleware/verifyOwnership");
const Monitor = require("../models/Monitor");
router.post(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.createCheck
);
router.get(
"/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.getChecks
);
router.post(
"/delete/:monitorId",
verifyOwnership(Monitor, "monitorId"),
checkController.deleteChecks
);
module.exports = router;