mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-05 07:59:30 -05:00
Merge branch 'master' into feat/alert-routes
This commit is contained in:
@@ -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,
|
||||
};
|
||||
@@ -16,6 +16,10 @@ const connect = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
//****************************************
|
||||
// Users
|
||||
//****************************************
|
||||
|
||||
/**
|
||||
* Insert a User
|
||||
* @async
|
||||
@@ -55,6 +59,10 @@ const getUserByEmail = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
//****************************************
|
||||
// Monitors
|
||||
//****************************************
|
||||
|
||||
/**
|
||||
* Update a user by ID
|
||||
* @async
|
||||
@@ -194,6 +202,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,
|
||||
@@ -205,4 +276,7 @@ module.exports = {
|
||||
createMonitor,
|
||||
deleteMonitor,
|
||||
editMonitor,
|
||||
createCheck,
|
||||
getChecks,
|
||||
deleteChecks,
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
// Testing email service
|
||||
// app.use('/sendEmail', async (req, res) => {
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user