Merge pull request #493 from bluewave-labs/feat/be/delete-notificatons-on-monitor-delete
Feat/be/delete notificatons on monitor delete
This commit is contained in:
1 file changed
+24
-9
@@ -9,7 +9,6 @@ const {
|
|||||||
|
|
||||||
const SERVICE_NAME = "monitorController";
|
const SERVICE_NAME = "monitorController";
|
||||||
const { errorMessages, successMessages } = require("../utils/messages");
|
const { errorMessages, successMessages } = require("../utils/messages");
|
||||||
const { error } = require("winston");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all monitors
|
* Returns all monitors
|
||||||
@@ -47,7 +46,8 @@ const getMonitorById = async (req, res, next) => {
|
|||||||
await getMonitorByIdQueryValidation.validateAsync(req.query);
|
await getMonitorByIdQueryValidation.validateAsync(req.query);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
error.message = error.details[0].message;
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -83,6 +83,16 @@ const getMonitorsByUserId = async (req, res, next) => {
|
|||||||
try {
|
try {
|
||||||
await getMonitorsByUserIdValidation.validateAsync(req.params);
|
await getMonitorsByUserIdValidation.validateAsync(req.params);
|
||||||
await getMonitorsByUserIdQueryValidation.validateAsync(req.query);
|
await getMonitorsByUserIdQueryValidation.validateAsync(req.query);
|
||||||
|
} catch (error) {
|
||||||
|
error.status = 422;
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
|
next(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const userId = req.params.userId;
|
const userId = req.params.userId;
|
||||||
const monitors = await req.db.getMonitorsByUserId(req, res);
|
const monitors = await req.db.getMonitorsByUserId(req, res);
|
||||||
|
|
||||||
@@ -112,7 +122,9 @@ const createMonitor = async (req, res, next) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.message = error.details[0].message;
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
|
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -143,22 +155,24 @@ const createMonitor = async (req, res, next) => {
|
|||||||
|
|
||||||
const deleteMonitor = async (req, res, next) => {
|
const deleteMonitor = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await getMonitorByIdValidation.validateAsync(req.params);
|
await getMonitorByIdParamValidation.validateAsync(req.params);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.message = error.details[0].message;
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const monitor = await req.db.deleteMonitor(req, res, next);
|
const monitor = await req.db.deleteMonitor(req, res, next);
|
||||||
// Delete associated checks and alerts
|
// Delete associated checks,alerts,and notifications
|
||||||
await req.jobQueue.deleteJob(monitor);
|
await req.jobQueue.deleteJob(monitor);
|
||||||
await req.db.deleteChecks(monitor._id);
|
await req.db.deleteChecks(monitor._id);
|
||||||
await req.db.deleteAlertByMonitorId(monitor._id);
|
await req.db.deleteAlertByMonitorId(monitor._id);
|
||||||
await req.db.deleteNotificationByMonitorId(monitor._id);
|
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
* We should remove all checks and alerts associated with this monitor
|
* We should remove all checks and alerts associated with this monitor
|
||||||
@@ -196,12 +210,13 @@ const deleteAllMonitors = async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
const editMonitor = async (req, res, next) => {
|
const editMonitor = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await getMonitorByIdValidation.validateAsync(req.params);
|
await getMonitorByIdParamValidation.validateAsync(req.params);
|
||||||
await editMonitorBodyValidation.validateAsync(req.body);
|
await editMonitorBodyValidation.validateAsync(req.body);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.message = error.details[0].message;
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user