Ack Field in Checks
This commit is contained in:
1 parent
faa2a2d965
commit
30d85e5712
6 files changed
+42
-26
No files matched your search
@@ -32,13 +32,11 @@ const IncidentTable = ({
|
|||||||
const selectedMonitorDetails = monitors?.[selectedMonitor];
|
const selectedMonitorDetails = monitors?.[selectedMonitor];
|
||||||
const selectedMonitorType = selectedMonitorDetails?.type;
|
const selectedMonitorType = selectedMonitorDetails?.type;
|
||||||
|
|
||||||
const status = filter === "resolved" ? true : false;
|
|
||||||
|
|
||||||
const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] =
|
const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] =
|
||||||
useFetchChecksByMonitor({
|
useFetchChecksByMonitor({
|
||||||
monitorId: selectedMonitor === "0" ? undefined : selectedMonitor,
|
monitorId: selectedMonitor === "0" ? undefined : selectedMonitor,
|
||||||
type: selectedMonitorType,
|
type: selectedMonitorType,
|
||||||
status: status,
|
status: false,
|
||||||
sortOrder: "desc",
|
sortOrder: "desc",
|
||||||
limit: null,
|
limit: null,
|
||||||
dateRange,
|
dateRange,
|
||||||
@@ -50,7 +48,7 @@ const IncidentTable = ({
|
|||||||
|
|
||||||
const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] =
|
const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] =
|
||||||
useFetchChecksTeam({
|
useFetchChecksTeam({
|
||||||
status: status,
|
status: false,
|
||||||
sortOrder: "desc",
|
sortOrder: "desc",
|
||||||
limit: null,
|
limit: null,
|
||||||
dateRange,
|
dateRange,
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ class NetworkService {
|
|||||||
*/
|
*/
|
||||||
async updateCheckStatus(config) {
|
async updateCheckStatus(config) {
|
||||||
return this.axiosInstance.put(`/checks/${config.checkId}`, {
|
return this.axiosInstance.put(`/checks/${config.checkId}`, {
|
||||||
status: config.status,
|
ack: config.ack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ class CheckController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { checkId } = req.params;
|
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({
|
return res.success({
|
||||||
msg: this.stringService.checkUpdateStatus,
|
msg: this.stringService.checkUpdateStatus,
|
||||||
@@ -143,13 +143,9 @@ class CheckController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { monitorId, target } = req.params;
|
const { monitorId, target } = req.params;
|
||||||
const { status } = req.body;
|
const { ack } = req.body;
|
||||||
|
|
||||||
const updatedChecks = await this.db.updateAllChecksStatus(
|
const updatedChecks = await this.db.updateAllChecksStatus(monitorId, ack, target);
|
||||||
monitorId,
|
|
||||||
status,
|
|
||||||
target
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.checkUpdateStatus,
|
msg: this.stringService.checkUpdateStatus,
|
||||||
|
|||||||
@@ -64,6 +64,23 @@ const BaseCheckSchema = mongoose.Schema({
|
|||||||
default: Date.now,
|
default: Date.now,
|
||||||
expires: 60 * 60 * 24 * 30, // 30 days
|
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,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -239,20 +239,25 @@ const getChecksByTeam = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the status of a check
|
* Update the acknowledgment status of a check
|
||||||
* @async
|
* @async
|
||||||
* @param {string} checkId
|
* @param {string} checkId - The ID of the check to update
|
||||||
* @param {boolean} status
|
* @param {boolean} ack - The acknowledgment status to set
|
||||||
* @returns {Promise<Check>}
|
* @returns {Promise<Check>}
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
const updateCheckStatus = async (checkId, status) => {
|
const updateCheckStatus = async (checkId, ack) => {
|
||||||
try {
|
try {
|
||||||
const updatedCheck = await Check.findOneAndUpdate(
|
const updatedCheck = await Check.findOneAndUpdate(
|
||||||
{ _id: checkId },
|
{ _id: checkId },
|
||||||
{ status },
|
{ $set: { ack, ackAt: new Date() } },
|
||||||
{ new: true }
|
{ new: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!updatedCheck) {
|
||||||
|
throw new Error("Check not found");
|
||||||
|
}
|
||||||
|
|
||||||
return updatedCheck;
|
return updatedCheck;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
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
|
* @async
|
||||||
* @param {string} id
|
* @param {string} id - The monitor ID or team ID
|
||||||
* @param {boolean} status
|
* @param {boolean} ack - The acknowledgment status to set
|
||||||
* @param {string} target
|
* @param {string} target - The target type ('monitor' or 'team')
|
||||||
* @returns {Promise<number>}
|
* @returns {Promise<number>}
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
const updateAllChecksStatus = async (id, status, target) => {
|
const updateAllChecksStatus = async (id, ack, target) => {
|
||||||
try {
|
try {
|
||||||
const updatedChecks = await Check.updateMany(
|
const updatedChecks = await Check.updateMany(
|
||||||
target === "monitor" ? { monitorId: id } : { teamId: id },
|
target === "monitor" ? { monitorId: id } : { teamId: id },
|
||||||
{ $set: { status } }
|
{ $set: { ack, ackAt: new Date() } }
|
||||||
);
|
);
|
||||||
return updatedChecks.modifiedCount;
|
return updatedChecks.modifiedCount;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ const createCheckBodyValidation = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateCheckStatusBodyValidation = joi.object({
|
const updateCheckStatusBodyValidation = joi.object({
|
||||||
status: joi.boolean(),
|
ack: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateCheckStatusParamValidation = joi.object({
|
const updateCheckStatusParamValidation = joi.object({
|
||||||
@@ -299,7 +299,7 @@ const updateCheckStatusParamValidation = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const updateAllChecksStatusBodyValidation = joi.object({
|
const updateAllChecksStatusBodyValidation = joi.object({
|
||||||
status: joi.boolean(),
|
ack: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getChecksParamValidation = joi.object({
|
const getChecksParamValidation = joi.object({
|
||||||
|
|||||||
Reference in new issue
Block a user