implement deleting maintenance window
This commit is contained in:
1 parent
f48b769baa
commit
335098e2a8
4 files changed
+35
No files matched your search
@@ -2,6 +2,7 @@ const {
|
||||
createMaintenanceWindowBodyValidation,
|
||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||
deleteMaintenanceWindowByIdParamValidation,
|
||||
} = require("../validation/joi");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const { getTokenFromHeaders } = require("../utils/utils");
|
||||
@@ -116,8 +117,34 @@ const getMaintenanceWindowsByMonitorId = async (req, res, next) => {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteMaintenanceWindow = async (req, res, next) => {
|
||||
try {
|
||||
await deleteMaintenanceWindowByIdParamValidation.validateAsync(req.params);
|
||||
} catch (error) {
|
||||
error.status = 422;
|
||||
error.service = SERVICE_NAME;
|
||||
error.message =
|
||||
error.details?.[0]?.message || error.message || "Validation Error";
|
||||
next(error);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await req.db.deleteMaintenanceWindowById(req.params.id);
|
||||
return res.status(201).json({
|
||||
success: true,
|
||||
msg: successMessages.MAINTENANCE_WINDOW_DELETE,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "deleteMaintenanceWindow")
|
||||
: null;
|
||||
}
|
||||
};
|
||||
module.exports = {
|
||||
createMaintenanceWindows,
|
||||
getMaintenanceWindowsByTeamId,
|
||||
getMaintenanceWindowsByMonitorId,
|
||||
deleteMaintenanceWindow,
|
||||
};
|
||||
@@ -13,4 +13,6 @@ router.get(
|
||||
|
||||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
||||
|
||||
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
||||
|
||||
module.exports = router;
|
||||
@@ -96,6 +96,7 @@ const successMessages = {
|
||||
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
||||
MAINTENANCE_WINDOW_GET_BY_TEAM:
|
||||
"Got Maintenance Windows by Team successfully",
|
||||
MAINTENANCE_WINDOW_DELETE: "Maintenance Window deleted successfully",
|
||||
|
||||
//Ping Operations
|
||||
PING_SUCCESS: "Success",
|
||||
|
||||
@@ -384,6 +384,10 @@ const getMaintenanceWindowsByMonitorIdParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
const deleteMaintenanceWindowByIdParamValidation = joi.object({
|
||||
id: joi.string().required(),
|
||||
});
|
||||
|
||||
//****************************************
|
||||
// SettingsValidation
|
||||
//****************************************
|
||||
@@ -452,5 +456,6 @@ module.exports = {
|
||||
createMaintenanceWindowBodyValidation,
|
||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||
deleteMaintenanceWindowByIdParamValidation,
|
||||
updateAppSettingsBodyValidation,
|
||||
};
|
||||
Reference in new issue
Block a user