add put route, controller, and db method for maintenance window

This commit is contained in:
Alex Holliday committed 2024-10-09 11:33:12 +08:00
1 parent 7c5c821fdd
commit 114cfd6cb7
6 files changed
+63

No files matched your search

@@ -142,9 +142,37 @@ const deleteMaintenanceWindow = async (req, res, next) => {
: null;
}
};
const editMaintenanceWindow = async (req, res, next) => {
try {
await editMaintenanceWindowByIdParamValidation.validateAsync(req.params);
await editMaintenanceByIdWindowBodyValidation.validateAsync(req.body);
} 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.editMaintenanceWindow(req.params.id, req.body);
return res.status(201).json({
success: true,
msg: successMessages.MAINTENANCE_WINDOW_EDIT,
});
} catch (error) {
error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined
? (error.method = "editMaintenanceWindow")
: null;
}
};
module.exports = {
createMaintenanceWindows,
getMaintenanceWindowsByTeamId,
getMaintenanceWindowsByMonitorId,
deleteMaintenanceWindow,
editMaintenanceWindow,
};
+2
View File
@@ -123,6 +123,7 @@ const {
deleteMaintenanceWindowById,
deleteMaintenanceWindowByMonitorId,
deleteMaintenanceWindowByUserId,
editMaintenanceWindowById,
} = require("./modules/maintenanceWindowModule");
//****************************************
@@ -186,6 +187,7 @@ module.exports = {
deleteMaintenanceWindowById,
deleteMaintenanceWindowByMonitorId,
deleteMaintenanceWindowByUserId,
editMaintenanceWindowById,
createNotification,
getNotificationsByMonitorId,
deleteNotificationsByMonitorId,
@@ -188,6 +188,18 @@ const deleteMaintenanceWindowByUserId = async (userId) => {
}
};
const editMaintenanceWindowById = async (
maintenanceWindowId,
maintenanceWindowData
) => {
try {
} catch (error) {
error.service = SERVICE_NAME;
error.method = "editMaintenanceWindowById";
throw error;
}
};
module.exports = {
createMaintenanceWindow,
getMaintenanceWindowsByTeamId,
@@ -195,4 +207,5 @@ module.exports = {
deleteMaintenanceWindowById,
deleteMaintenanceWindowByMonitorId,
deleteMaintenanceWindowByUserId,
editMaintenanceWindowById,
};
+2
View File
@@ -13,6 +13,8 @@ router.get(
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
router.put("/:id", maintenanceWindowController.editMaintenanceWindow);
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
module.exports = router;
+1
View File
@@ -97,6 +97,7 @@ const successMessages = {
MAINTENANCE_WINDOW_GET_BY_TEAM:
"Got Maintenance Windows by Team successfully",
MAINTENANCE_WINDOW_DELETE: "Maintenance Window deleted successfully",
MAINTENANCE_WINDOW_EDIT: "Maintenance Window edited successfully",
//Ping Operations
PING_SUCCESS: "Success",
+17
View File
@@ -1,5 +1,7 @@
const exp = require("constants");
const joi = require("joi");
const { normalize } = require("path");
const { start } = require("repl");
//****************************************
// Custom Validators
@@ -388,6 +390,19 @@ const deleteMaintenanceWindowByIdParamValidation = joi.object({
id: joi.string().required(),
});
const editMaintenanceWindowByIdParamValidation = joi.object({
id: joi.string().required(),
});
const editMaintenanceByIdWindowBodyValidation = joi.object({
active: joi.boolean(),
name: joi.string(),
repeat: joi.number(),
start: joi.date(),
end: joi.date(),
expiry: joi.date(),
});
//****************************************
// SettingsValidation
//****************************************
@@ -457,5 +472,7 @@ module.exports = {
getMaintenanceWindowsByTeamIdQueryValidation,
getMaintenanceWindowsByMonitorIdParamValidation,
deleteMaintenanceWindowByIdParamValidation,
editMaintenanceWindowByIdParamValidation,
editMaintenanceByIdWindowBodyValidation,
updateAppSettingsBodyValidation,
};