Add route, controller, and DB methods for fetching maintenance window by ID
This commit is contained in:
1 parent
114cfd6cb7
commit
e3c0944062
10 files changed
+143
-16
No files matched your search
@@ -1,5 +1,6 @@
|
||||
const {
|
||||
createMaintenanceWindowBodyValidation,
|
||||
getMaintenanceWindowByIdParamValidation,
|
||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||
deleteMaintenanceWindowByIdParamValidation,
|
||||
@@ -50,6 +51,35 @@ const createMaintenanceWindows = async (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getMaintenanceWindowById = async (req, res, next) => {
|
||||
try {
|
||||
await getMaintenanceWindowByIdParamValidation.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 {
|
||||
const maintenanceWindow = await req.db.getMaintenanceWindowById(
|
||||
req.params.id
|
||||
);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.MAINTENANCE_WINDOW_GET_BY_ID,
|
||||
data: maintenanceWindow,
|
||||
});
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
error.method === undefined
|
||||
? (error.method = "getMaintenanceWindowById")
|
||||
: null;
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
const getMaintenanceWindowsByTeamId = async (req, res, next) => {
|
||||
try {
|
||||
await getMaintenanceWindowsByTeamIdQueryValidation.validateAsync(req.query);
|
||||
@@ -171,6 +201,7 @@ const editMaintenanceWindow = async (req, res, next) => {
|
||||
|
||||
module.exports = {
|
||||
createMaintenanceWindows,
|
||||
getMaintenanceWindowById,
|
||||
getMaintenanceWindowsByTeamId,
|
||||
getMaintenanceWindowsByMonitorId,
|
||||
deleteMaintenanceWindow,
|
||||
|
||||
@@ -118,6 +118,7 @@ const {
|
||||
//****************************************
|
||||
const {
|
||||
createMaintenanceWindow,
|
||||
getMaintenanceWindowById,
|
||||
getMaintenanceWindowsByTeamId,
|
||||
getMaintenanceWindowsByMonitorId,
|
||||
deleteMaintenanceWindowById,
|
||||
@@ -183,6 +184,7 @@ module.exports = {
|
||||
deletePageSpeedChecksByMonitorId,
|
||||
createMaintenanceWindow,
|
||||
getMaintenanceWindowsByTeamId,
|
||||
getMaintenanceWindowById,
|
||||
getMaintenanceWindowsByMonitorId,
|
||||
deleteMaintenanceWindowById,
|
||||
deleteMaintenanceWindowByMonitorId,
|
||||
|
||||
@@ -45,6 +45,19 @@ const createMaintenanceWindow = async (maintenanceWindowData) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getMaintenanceWindowById = async (maintenanceWindowId) => {
|
||||
try {
|
||||
const maintenanceWindow = await MaintenanceWindow.findById({
|
||||
_id: maintenanceWindowId,
|
||||
});
|
||||
return maintenanceWindow;
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getMaintenanceWindowById";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously retrieves all MaintenanceWindow documents associated with a specific team ID.
|
||||
* @async
|
||||
@@ -202,6 +215,7 @@ const editMaintenanceWindowById = async (
|
||||
|
||||
module.exports = {
|
||||
createMaintenanceWindow,
|
||||
getMaintenanceWindowById,
|
||||
getMaintenanceWindowsByTeamId,
|
||||
getMaintenanceWindowsByMonitorId,
|
||||
deleteMaintenanceWindowById,
|
||||
|
||||
@@ -13,6 +13,8 @@ router.get(
|
||||
|
||||
router.get("/team/", maintenanceWindowController.getMaintenanceWindowsByTeamId);
|
||||
|
||||
router.get("/:id", maintenanceWindowController.getMaintenanceWindowById);
|
||||
|
||||
router.put("/:id", maintenanceWindowController.editMaintenanceWindow);
|
||||
|
||||
router.delete("/:id", maintenanceWindowController.deleteMaintenanceWindow);
|
||||
|
||||
@@ -93,6 +93,7 @@ const successMessages = {
|
||||
JOB_QUEUE_RESUME_JOB: "Job resumed successfully",
|
||||
|
||||
//Maintenance Window Controller
|
||||
MAINTENANCE_WINDOW_GET_BY_ID: "Got Maintenance Window by Id successfully",
|
||||
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
||||
MAINTENANCE_WINDOW_GET_BY_TEAM:
|
||||
"Got Maintenance Windows by Team successfully",
|
||||
|
||||
@@ -374,6 +374,10 @@ const createMaintenanceWindowBodyValidation = joi.object({
|
||||
expiry: joi.date(),
|
||||
});
|
||||
|
||||
const getMaintenanceWindowByIdParamValidation = joi.object({
|
||||
id: joi.string().required(),
|
||||
});
|
||||
|
||||
const getMaintenanceWindowsByTeamIdQueryValidation = joi.object({
|
||||
active: joi.boolean(),
|
||||
page: joi.number(),
|
||||
@@ -469,6 +473,7 @@ module.exports = {
|
||||
deletePageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckBodyValidation,
|
||||
createMaintenanceWindowBodyValidation,
|
||||
getMaintenanceWindowByIdParamValidation,
|
||||
getMaintenanceWindowsByTeamIdQueryValidation,
|
||||
getMaintenanceWindowsByMonitorIdParamValidation,
|
||||
deleteMaintenanceWindowByIdParamValidation,
|
||||
|
||||
Reference in new issue
Block a user