add put route, controller, and db method for maintenance window
This commit is contained in:
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;
|
: 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 = {
|
module.exports = {
|
||||||
createMaintenanceWindows,
|
createMaintenanceWindows,
|
||||||
getMaintenanceWindowsByTeamId,
|
getMaintenanceWindowsByTeamId,
|
||||||
getMaintenanceWindowsByMonitorId,
|
getMaintenanceWindowsByMonitorId,
|
||||||
deleteMaintenanceWindow,
|
deleteMaintenanceWindow,
|
||||||
|
editMaintenanceWindow,
|
||||||
};
|
};
|
||||||
@@ -123,6 +123,7 @@ const {
|
|||||||
deleteMaintenanceWindowById,
|
deleteMaintenanceWindowById,
|
||||||
deleteMaintenanceWindowByMonitorId,
|
deleteMaintenanceWindowByMonitorId,
|
||||||
deleteMaintenanceWindowByUserId,
|
deleteMaintenanceWindowByUserId,
|
||||||
|
editMaintenanceWindowById,
|
||||||
} = require("./modules/maintenanceWindowModule");
|
} = require("./modules/maintenanceWindowModule");
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -186,6 +187,7 @@ module.exports = {
|
|||||||
deleteMaintenanceWindowById,
|
deleteMaintenanceWindowById,
|
||||||
deleteMaintenanceWindowByMonitorId,
|
deleteMaintenanceWindowByMonitorId,
|
||||||
deleteMaintenanceWindowByUserId,
|
deleteMaintenanceWindowByUserId,
|
||||||
|
editMaintenanceWindowById,
|
||||||
createNotification,
|
createNotification,
|
||||||
getNotificationsByMonitorId,
|
getNotificationsByMonitorId,
|
||||||
deleteNotificationsByMonitorId,
|
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 = {
|
module.exports = {
|
||||||
createMaintenanceWindow,
|
createMaintenanceWindow,
|
||||||
getMaintenanceWindowsByTeamId,
|
getMaintenanceWindowsByTeamId,
|
||||||
@@ -195,4 +207,5 @@ module.exports = {
|
|||||||
deleteMaintenanceWindowById,
|
deleteMaintenanceWindowById,
|
||||||
deleteMaintenanceWindowByMonitorId,
|
deleteMaintenanceWindowByMonitorId,
|
||||||
deleteMaintenanceWindowByUserId,
|
deleteMaintenanceWindowByUserId,
|
||||||
|
editMaintenanceWindowById,
|
||||||
};
|
};
|
||||||
@@ -13,6 +13,8 @@ router.get(
|
|||||||
|
|
||||||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
||||||
|
|
||||||
|
router.put("/:id", maintenanceWindowController.editMaintenanceWindow);
|
||||||
|
|
||||||
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -97,6 +97,7 @@ const successMessages = {
|
|||||||
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",
|
MAINTENANCE_WINDOW_DELETE: "Maintenance Window deleted successfully",
|
||||||
|
MAINTENANCE_WINDOW_EDIT: "Maintenance Window edited successfully",
|
||||||
|
|
||||||
//Ping Operations
|
//Ping Operations
|
||||||
PING_SUCCESS: "Success",
|
PING_SUCCESS: "Success",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
const exp = require("constants");
|
||||||
const joi = require("joi");
|
const joi = require("joi");
|
||||||
const { normalize } = require("path");
|
const { normalize } = require("path");
|
||||||
|
const { start } = require("repl");
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// Custom Validators
|
// Custom Validators
|
||||||
@@ -388,6 +390,19 @@ const deleteMaintenanceWindowByIdParamValidation = joi.object({
|
|||||||
id: joi.string().required(),
|
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
|
// SettingsValidation
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -457,5 +472,7 @@ module.exports = {
|
|||||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||||
deleteMaintenanceWindowByIdParamValidation,
|
deleteMaintenanceWindowByIdParamValidation,
|
||||||
|
editMaintenanceWindowByIdParamValidation,
|
||||||
|
editMaintenanceByIdWindowBodyValidation,
|
||||||
updateAppSettingsBodyValidation,
|
updateAppSettingsBodyValidation,
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user