From 183c13fe53c4e968c0e86a68dceb0dfe85ee3fe5 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Tue, 24 Jun 2025 14:44:02 +0530 Subject: [PATCH] Naming Changes in BE --- client/src/Hooks/checkHooks.js | 7 +++++- .../Components/IncidentTable/index.jsx | 2 ++ client/src/Utils/NetworkService.js | 4 ++++ server/controllers/checkController.js | 23 +++++++++++-------- server/db/mongo/modules/checkModule.js | 23 +++++++++++-------- server/routes/checkRoute.js | 4 ++-- server/validation/joi.js | 6 +++-- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/client/src/Hooks/checkHooks.js b/client/src/Hooks/checkHooks.js index 683b89b20..98fb0cfd5 100644 --- a/client/src/Hooks/checkHooks.js +++ b/client/src/Hooks/checkHooks.js @@ -8,6 +8,7 @@ const useFetchChecksTeam = ({ limit, dateRange, filter, + ack, page, rowsPerPage, enabled = true, @@ -29,6 +30,7 @@ const useFetchChecksTeam = ({ limit, dateRange, filter, + ack, page, rowsPerPage, }; @@ -47,7 +49,7 @@ const useFetchChecksTeam = ({ }; fetchChecks(); - }, [status, sortOrder, limit, dateRange, filter, page, rowsPerPage, enabled]); + }, [status, sortOrder, limit, dateRange, filter, ack, page, rowsPerPage, enabled]); return [checks, checksCount, isLoading, networkError]; }; @@ -60,6 +62,7 @@ const useFetchChecksByMonitor = ({ limit, dateRange, filter, + ack, page, rowsPerPage, enabled = true, @@ -83,6 +86,7 @@ const useFetchChecksByMonitor = ({ limit, dateRange, filter, + ack, page, rowsPerPage, }; @@ -109,6 +113,7 @@ const useFetchChecksByMonitor = ({ limit, dateRange, filter, + ack, page, rowsPerPage, enabled, diff --git a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx index 175649961..bc5eaa5ca 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx +++ b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx @@ -41,6 +41,7 @@ const IncidentTable = ({ limit: null, dateRange, filter: filter === "resolved" ? "all" : filter, + ack: filter === "resolved" ? true : false, page: page, rowsPerPage: rowsPerPage, enabled: selectedMonitor !== "0", @@ -53,6 +54,7 @@ const IncidentTable = ({ limit: null, dateRange, filter: filter === "resolved" ? "all" : filter, + ack: filter === "resolved" ? true : false, page: page, rowsPerPage: rowsPerPage, enabled: selectedMonitor === "0", diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index f953fc143..718b593de 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -549,6 +549,7 @@ class NetworkService { * @param {number} config.limit - The maximum number of checks to retrieve. * @param {string} config.dateRange - The range of dates for which to retrieve checks. * @param {string} config.filter - The filter to apply to the checks. + * @param {boolean} config.ack - The acknowledgment status to apply to the checks. * @param {number} config.page - The page number to retrieve in a paginated list. * @param {number} config.rowsPerPage - The number of rows per page in a paginated list. * @returns {Promise} The response from the axios GET request. @@ -562,6 +563,7 @@ class NetworkService { if (config.limit) params.append("limit", config.limit); if (config.dateRange) params.append("dateRange", config.dateRange); if (config.filter) params.append("filter", config.filter); + if (config.ack !== undefined) params.append("ack", config.ack); if (config.page) params.append("page", config.page); if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage); if (config.status !== undefined) params.append("status", config.status); @@ -581,6 +583,7 @@ class NetworkService { * @param {number} config.limit - The maximum number of checks to retrieve. * @param {string} config.dateRange - The range of dates for which to retrieve checks. * @param {string} config.filter - The filter to apply to the checks. + * @param {boolean} config.ack - The acknowledgment status to apply to the checks. * @param {number} config.page - The page number to retrieve in a paginated list. * @param {number} config.rowsPerPage - The number of rows per page in a paginated list. * @returns {Promise} The response from the axios GET request. @@ -592,6 +595,7 @@ class NetworkService { if (config.limit) params.append("limit", config.limit); if (config.dateRange) params.append("dateRange", config.dateRange); if (config.filter) params.append("filter", config.filter); + if (config.ack !== undefined) params.append("ack", config.ack); if (config.page) params.append("page", config.page); if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage); if (config.status !== undefined) params.append("status", config.status); diff --git a/server/controllers/checkController.js b/server/controllers/checkController.js index e3d3436e2..0c7b145e8 100755 --- a/server/controllers/checkController.js +++ b/server/controllers/checkController.js @@ -58,13 +58,15 @@ class CheckController { try { const { monitorId } = req.params; - let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query; + let { type, sortOrder, dateRange, filter, ack, page, rowsPerPage, status } = + req.query; const result = await this.db.getChecksByMonitor({ monitorId, type, sortOrder, dateRange, filter, + ack, page, rowsPerPage, status, @@ -88,13 +90,14 @@ class CheckController { return; } try { - let { sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query; + let { sortOrder, dateRange, filter, ack, page, rowsPerPage, status } = req.query; const { teamId } = req.user; const checkData = await this.db.getChecksByTeam({ sortOrder, dateRange, filter, + ack, page, rowsPerPage, teamId, @@ -109,7 +112,7 @@ class CheckController { } }; - updateCheckStatus = async (req, res, next) => { + ackCheck = async (req, res, next) => { try { await updateCheckStatusBodyValidation.validateAsync(req.body); } catch (error) { @@ -120,19 +123,20 @@ class CheckController { try { const { checkId } = req.params; const { ack } = req.body; + const { teamId } = req.user; - const updatedCheck = await this.db.updateCheckStatus(checkId, ack); + const updatedCheck = await this.db.ackCheck(checkId, teamId, ack); return res.success({ msg: this.stringService.checkUpdateStatus, data: updatedCheck, }); } catch (error) { - next(handleError(error, SERVICE_NAME, "updateCheckStatus")); + next(handleError(error, SERVICE_NAME, "ackCheck")); } }; - updateAllChecksStatus = async (req, res, next) => { + ackAllChecks = async (req, res, next) => { try { await updateCheckStatusParamValidation.validateAsync(req.params); await updateAllChecksStatusBodyValidation.validateAsync(req.body); @@ -142,17 +146,18 @@ class CheckController { } try { - const { monitorId, target } = req.params; + const { monitorId, path } = req.params; const { ack } = req.body; + const { teamId } = req.user; - const updatedChecks = await this.db.updateAllChecksStatus(monitorId, ack, target); + const updatedChecks = await this.db.ackAllChecks(monitorId, teamId, ack, path); return res.success({ msg: this.stringService.checkUpdateStatus, data: updatedChecks, }); } catch (error) { - next(handleError(error, SERVICE_NAME, "updateAllChecksStatus")); + next(handleError(error, SERVICE_NAME, "ackAllChecks")); } }; diff --git a/server/db/mongo/modules/checkModule.js b/server/db/mongo/modules/checkModule.js index 0a4b1ad63..96c07e52e 100755 --- a/server/db/mongo/modules/checkModule.js +++ b/server/db/mongo/modules/checkModule.js @@ -63,6 +63,7 @@ const getChecksByMonitor = async ({ sortOrder, dateRange, filter, + ack, page, rowsPerPage, status, @@ -75,6 +76,7 @@ const getChecksByMonitor = async ({ const matchStage = { monitorId: ObjectId.createFromHexString(monitorId), ...(typeof status !== "undefined" && { status }), + ...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }), ...(dateRangeLookup[dateRange] && { createdAt: { $gte: dateRangeLookup[dateRange], @@ -153,6 +155,7 @@ const getChecksByTeam = async ({ sortOrder, dateRange, filter, + ack, page, rowsPerPage, teamId, @@ -165,6 +168,7 @@ const getChecksByTeam = async ({ const matchStage = { teamId: ObjectId.createFromHexString(teamId), status: status, + ...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }), ...(dateRangeLookup[dateRange] && { createdAt: { $gte: dateRangeLookup[dateRange], @@ -242,14 +246,15 @@ const getChecksByTeam = async ({ * Update the acknowledgment status of a check * @async * @param {string} checkId - The ID of the check to update + * @param {string} teamId - The ID of the team * @param {boolean} ack - The acknowledgment status to set * @returns {Promise} * @throws {Error} */ -const updateCheckStatus = async (checkId, ack) => { +const ackCheck = async (checkId, teamId, ack) => { try { const updatedCheck = await Check.findOneAndUpdate( - { _id: checkId }, + { _id: checkId, teamId: teamId }, { $set: { ack, ackAt: new Date() } }, { new: true } ); @@ -261,7 +266,7 @@ const updateCheckStatus = async (checkId, ack) => { return updatedCheck; } catch (error) { error.service = SERVICE_NAME; - error.method = "updateCheckStatus"; + error.method = "ackCheck"; throw error; } }; @@ -271,20 +276,20 @@ const updateCheckStatus = async (checkId, ack) => { * @async * @param {string} id - The monitor ID or team ID * @param {boolean} ack - The acknowledgment status to set - * @param {string} target - The target type ('monitor' or 'team') + * @param {string} path - The path type ('monitor' or 'team') * @returns {Promise} * @throws {Error} */ -const updateAllChecksStatus = async (id, ack, target) => { +const ackAllChecks = async (monitorId, teamId, ack, path) => { try { const updatedChecks = await Check.updateMany( - target === "monitor" ? { monitorId: id } : { teamId: id }, + path === "monitor" ? { monitorId } : { teamId }, { $set: { ack, ackAt: new Date() } } ); return updatedChecks.modifiedCount; } catch (error) { error.service = SERVICE_NAME; - error.method = "updateAllChecksStatus"; + error.method = "ackAllChecks"; throw error; } }; @@ -370,8 +375,8 @@ export { createChecks, getChecksByMonitor, getChecksByTeam, - updateCheckStatus, - updateAllChecksStatus, + ackCheck, + ackAllChecks, deleteChecks, deleteChecksByTeamId, updateChecksTTL, diff --git a/server/routes/checkRoute.js b/server/routes/checkRoute.js index c6d0c584f..19a03643c 100755 --- a/server/routes/checkRoute.js +++ b/server/routes/checkRoute.js @@ -20,9 +20,9 @@ class CheckRoutes { this.router.get("/:monitorId", this.checkController.getChecksByMonitor); - this.router.put("/:checkId", this.checkController.updateCheckStatus); + this.router.put("/:checkId", this.checkController.ackCheck); - this.router.put("/:monitorId/:target", this.checkController.updateAllChecksStatus); + this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks); this.router.post( "/:monitorId", diff --git a/server/validation/joi.js b/server/validation/joi.js index ff1fa65c5..593823f35 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -294,8 +294,8 @@ const updateCheckStatusBodyValidation = joi.object({ }); const updateCheckStatusParamValidation = joi.object({ - monitorId: joi.string(), - target: joi.string().allow("monitor", "team"), + monitorId: joi.string().optional(), + path: joi.string().valid("monitor", "team").required(), }); const updateAllChecksStatusBodyValidation = joi.object({ @@ -312,6 +312,7 @@ const getChecksQueryValidation = joi.object({ limit: joi.number(), dateRange: joi.string().valid("recent", "hour", "day", "week", "month", "all"), filter: joi.string().valid("all", "down", "resolve"), + ack: joi.boolean(), page: joi.number(), rowsPerPage: joi.number(), status: joi.boolean(), @@ -324,6 +325,7 @@ const getTeamChecksQueryValidation = joi.object({ limit: joi.number(), dateRange: joi.string().valid("hour", "day", "week", "month", "all"), filter: joi.string().valid("all", "down", "resolve"), + ack: joi.boolean(), page: joi.number(), rowsPerPage: joi.number(), status: joi.boolean(),