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,
|
createMaintenanceWindowBodyValidation,
|
||||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||||
|
deleteMaintenanceWindowByIdParamValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
const { getTokenFromHeaders } = require("../utils/utils");
|
const { getTokenFromHeaders } = require("../utils/utils");
|
||||||
@@ -116,8 +117,34 @@ const getMaintenanceWindowsByMonitorId = async (req, res, next) => {
|
|||||||
next(error);
|
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 = {
|
module.exports = {
|
||||||
createMaintenanceWindows,
|
createMaintenanceWindows,
|
||||||
getMaintenanceWindowsByTeamId,
|
getMaintenanceWindowsByTeamId,
|
||||||
getMaintenanceWindowsByMonitorId,
|
getMaintenanceWindowsByMonitorId,
|
||||||
|
deleteMaintenanceWindow,
|
||||||
};
|
};
|
||||||
@@ -13,4 +13,6 @@ router.get(
|
|||||||
|
|
||||||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
||||||
|
|
||||||
|
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -96,6 +96,7 @@ const successMessages = {
|
|||||||
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
||||||
MAINTENANCE_WINDOW_GET_BY_TEAM:
|
MAINTENANCE_WINDOW_GET_BY_TEAM:
|
||||||
"Got Maintenance Windows by Team successfully",
|
"Got Maintenance Windows by Team successfully",
|
||||||
|
MAINTENANCE_WINDOW_DELETE: "Maintenance Window deleted successfully",
|
||||||
|
|
||||||
//Ping Operations
|
//Ping Operations
|
||||||
PING_SUCCESS: "Success",
|
PING_SUCCESS: "Success",
|
||||||
|
|||||||
@@ -384,6 +384,10 @@ const getMaintenanceWindowsByMonitorIdParamValidation = joi.object({
|
|||||||
monitorId: joi.string().required(),
|
monitorId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const deleteMaintenanceWindowByIdParamValidation = joi.object({
|
||||||
|
id: joi.string().required(),
|
||||||
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// SettingsValidation
|
// SettingsValidation
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -452,5 +456,6 @@ module.exports = {
|
|||||||
createMaintenanceWindowBodyValidation,
|
createMaintenanceWindowBodyValidation,
|
||||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||||
|
deleteMaintenanceWindowByIdParamValidation,
|
||||||
updateAppSettingsBodyValidation,
|
updateAppSettingsBodyValidation,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user