Ack Field in Checks

This commit is contained in:
Br0wnHammer committed 2025-06-23 22:07:03 +05:30
1 parent faa2a2d965
commit 30d85e5712
6 files changed
+42 -26

No files matched your search

+17
View File
@@ -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,
},
});
/**
+16 -11
View File
@@ -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<Check>}
* @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<number>}
* @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) {