From 30d85e5712ffa17a688a5b1081d3b523a52fb597 Mon Sep 17 00:00:00 2001 From: Br0wnHammer Date: Mon, 23 Jun 2025 22:07:03 +0530 Subject: [PATCH] Ack Field in Checks --- .../Components/IncidentTable/index.jsx | 6 ++--- client/src/Utils/NetworkService.js | 2 +- server/controllers/checkController.js | 12 +++------ server/db/models/Check.js | 17 ++++++++++++ server/db/mongo/modules/checkModule.js | 27 +++++++++++-------- server/validation/joi.js | 4 +-- 6 files changed, 42 insertions(+), 26 deletions(-) diff --git a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx index b4bfbe9dc..175649961 100644 --- a/client/src/Pages/Incidents/Components/IncidentTable/index.jsx +++ b/client/src/Pages/Incidents/Components/IncidentTable/index.jsx @@ -32,13 +32,11 @@ const IncidentTable = ({ const selectedMonitorDetails = monitors?.[selectedMonitor]; const selectedMonitorType = selectedMonitorDetails?.type; - const status = filter === "resolved" ? true : false; - const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] = useFetchChecksByMonitor({ monitorId: selectedMonitor === "0" ? undefined : selectedMonitor, type: selectedMonitorType, - status: status, + status: false, sortOrder: "desc", limit: null, dateRange, @@ -50,7 +48,7 @@ const IncidentTable = ({ const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] = useFetchChecksTeam({ - status: status, + status: false, sortOrder: "desc", limit: null, dateRange, diff --git a/client/src/Utils/NetworkService.js b/client/src/Utils/NetworkService.js index 8625b69e3..f953fc143 100644 --- a/client/src/Utils/NetworkService.js +++ b/client/src/Utils/NetworkService.js @@ -612,7 +612,7 @@ class NetworkService { */ async updateCheckStatus(config) { return this.axiosInstance.put(`/checks/${config.checkId}`, { - status: config.status, + ack: config.ack, }); } diff --git a/server/controllers/checkController.js b/server/controllers/checkController.js index 15f889591..e3d3436e2 100755 --- a/server/controllers/checkController.js +++ b/server/controllers/checkController.js @@ -119,9 +119,9 @@ class CheckController { try { const { checkId } = req.params; - const { status } = req.body; + const { ack } = req.body; - const updatedCheck = await this.db.updateCheckStatus(checkId, status); + const updatedCheck = await this.db.updateCheckStatus(checkId, ack); return res.success({ msg: this.stringService.checkUpdateStatus, @@ -143,13 +143,9 @@ class CheckController { try { const { monitorId, target } = req.params; - const { status } = req.body; + const { ack } = req.body; - const updatedChecks = await this.db.updateAllChecksStatus( - monitorId, - status, - target - ); + const updatedChecks = await this.db.updateAllChecksStatus(monitorId, ack, target); return res.success({ msg: this.stringService.checkUpdateStatus, diff --git a/server/db/models/Check.js b/server/db/models/Check.js index 39c5281d2..8bb6cd028 100755 --- a/server/db/models/Check.js +++ b/server/db/models/Check.js @@ -64,6 +64,23 @@ const BaseCheckSchema = mongoose.Schema({ default: Date.now, expires: 60 * 60 * 24 * 30, // 30 days }, + /** + * Acknowledgment of the check. + * + * @type {Boolean} + */ + ack: { + type: Boolean, + default: false, + }, + /** + * Resolution date of the check (when the check was resolved). + * + * @type {Date} + */ + ackAt: { + type: Date, + }, }); /** diff --git a/server/db/mongo/modules/checkModule.js b/server/db/mongo/modules/checkModule.js index 6c64756ee..0a4b1ad63 100755 --- a/server/db/mongo/modules/checkModule.js +++ b/server/db/mongo/modules/checkModule.js @@ -239,20 +239,25 @@ const getChecksByTeam = async ({ }; /** - * Update the status of a check + * Update the acknowledgment status of a check * @async - * @param {string} checkId - * @param {boolean} status + * @param {string} checkId - The ID of the check to update + * @param {boolean} ack - The acknowledgment status to set * @returns {Promise} * @throws {Error} */ -const updateCheckStatus = async (checkId, status) => { +const updateCheckStatus = async (checkId, ack) => { try { const updatedCheck = await Check.findOneAndUpdate( { _id: checkId }, - { status }, + { $set: { ack, ackAt: new Date() } }, { new: true } ); + + if (!updatedCheck) { + throw new Error("Check not found"); + } + return updatedCheck; } catch (error) { error.service = SERVICE_NAME; @@ -262,19 +267,19 @@ const updateCheckStatus = async (checkId, status) => { }; /** - * Update the status of all checks for a monitor or team + * Update the acknowledgment status of all checks for a monitor or team * @async - * @param {string} id - * @param {boolean} status - * @param {string} target + * @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') * @returns {Promise} * @throws {Error} */ -const updateAllChecksStatus = async (id, status, target) => { +const updateAllChecksStatus = async (id, ack, target) => { try { const updatedChecks = await Check.updateMany( target === "monitor" ? { monitorId: id } : { teamId: id }, - { $set: { status } } + { $set: { ack, ackAt: new Date() } } ); return updatedChecks.modifiedCount; } catch (error) { diff --git a/server/validation/joi.js b/server/validation/joi.js index 4562e303e..ff1fa65c5 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -290,7 +290,7 @@ const createCheckBodyValidation = joi.object({ }); const updateCheckStatusBodyValidation = joi.object({ - status: joi.boolean(), + ack: joi.boolean(), }); const updateCheckStatusParamValidation = joi.object({ @@ -299,7 +299,7 @@ const updateCheckStatusParamValidation = joi.object({ }); const updateAllChecksStatusBodyValidation = joi.object({ - status: joi.boolean(), + ack: joi.boolean(), }); const getChecksParamValidation = joi.object({