Route for Updating a single Incident Status

This commit is contained in:
Br0wnHammer committed 2025-06-20 15:39:13 +05:30
1 parent 205e16a96d
commit e8908351a2
6 files changed
+81 -5

No files matched your search

@@ -42,7 +42,7 @@ const IncidentTable = ({
sortOrder: "desc", sortOrder: "desc",
limit: null, limit: null,
dateRange, dateRange,
filter: filter === "resolved" ? "resolve" : filter, filter: filter === "resolved" ? "all" : filter,
page: page, page: page,
rowsPerPage: rowsPerPage, rowsPerPage: rowsPerPage,
enabled: selectedMonitor !== "0", enabled: selectedMonitor !== "0",
@@ -54,7 +54,7 @@ const IncidentTable = ({
sortOrder: "desc", sortOrder: "desc",
limit: null, limit: null,
dateRange, dateRange,
filter: filter === "resolved" ? "resolve" : filter, filter: filter === "resolved" ? "all" : filter,
page: page, page: page,
rowsPerPage: rowsPerPage, rowsPerPage: rowsPerPage,
enabled: selectedMonitor === "0", enabled: selectedMonitor === "0",
+18
View File
@@ -598,6 +598,24 @@ class NetworkService {
return this.axiosInstance.get(`/checks/team?${params.toString()}`); return this.axiosInstance.get(`/checks/team?${params.toString()}`);
}; };
/**
* ************************************
* Update the status of a check
* ************************************
*
* @async
* @param {Object} config - The configuration object.
* @param {string} config.checkId - The ID of the check to update.
* @param {boolean} config.status - The status to update the check to.
* @returns {Promise<AxiosResponse>} The response from the axios PUT request.
*
*/
async updateCheckStatus(config) {
return this.axiosInstance.put(`/checks/${config.checkId}`, {
status: config.status,
});
}
/** /**
* ************************************ * ************************************
* Get all checks for a given user * Get all checks for a given user
+26 -1
View File
@@ -8,6 +8,7 @@ import {
deleteChecksParamValidation, deleteChecksParamValidation,
deleteChecksByTeamIdParamValidation, deleteChecksByTeamIdParamValidation,
updateChecksTTLBodyValidation, updateChecksTTLBodyValidation,
updateCheckStatusBodyValidation,
} from "../validation/joi.js"; } from "../validation/joi.js";
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import { getTokenFromHeaders } from "../utils/utils.js"; import { getTokenFromHeaders } from "../utils/utils.js";
@@ -85,7 +86,7 @@ class CheckController {
return; return;
} }
try { try {
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query; let { sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
const { teamId } = req.user; const { teamId } = req.user;
const checkData = await this.db.getChecksByTeam({ const checkData = await this.db.getChecksByTeam({
@@ -95,6 +96,7 @@ class CheckController {
page, page,
rowsPerPage, rowsPerPage,
teamId, teamId,
status,
}); });
return res.success({ return res.success({
msg: this.stringService.checkGet, msg: this.stringService.checkGet,
@@ -105,6 +107,29 @@ class CheckController {
} }
}; };
updateCheckStatus = async (req, res, next) => {
try {
await updateCheckStatusBodyValidation.validateAsync(req.body);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
}
try {
const { checkId } = req.params;
const { status } = req.body;
const updatedCheck = await this.db.updateCheckStatus(checkId, status);
return res.success({
msg: this.stringService.checkUpdateStatus,
data: updatedCheck,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "updateCheckStatus"));
}
};
deleteChecks = async (req, res, next) => { deleteChecks = async (req, res, next) => {
try { try {
await deleteChecksParamValidation.validateAsync(req.params); await deleteChecksParamValidation.validateAsync(req.params);
+28 -2
View File
@@ -68,7 +68,7 @@ const getChecksByMonitor = async ({
status, status,
}) => { }) => {
try { try {
status = typeof status !== "undefined" ? false : undefined; status = status === "true" ? true : status === "false" ? false : undefined;
page = parseInt(page); page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage); rowsPerPage = parseInt(rowsPerPage);
// Match // Match
@@ -156,13 +156,15 @@ const getChecksByTeam = async ({
page, page,
rowsPerPage, rowsPerPage,
teamId, teamId,
status,
}) => { }) => {
try { try {
status = status === "true" ? true : false;
page = parseInt(page); page = parseInt(page);
rowsPerPage = parseInt(rowsPerPage); rowsPerPage = parseInt(rowsPerPage);
const matchStage = { const matchStage = {
teamId: ObjectId.createFromHexString(teamId), teamId: ObjectId.createFromHexString(teamId),
status: false, status: status,
...(dateRangeLookup[dateRange] && { ...(dateRangeLookup[dateRange] && {
createdAt: { createdAt: {
$gte: dateRangeLookup[dateRange], $gte: dateRangeLookup[dateRange],
@@ -236,6 +238,29 @@ const getChecksByTeam = async ({
} }
}; };
/**
* Update the status of a check
* @async
* @param {string} checkId
* @param {boolean} status
* @returns {Promise<Check>}
* @throws {Error}
*/
const updateCheckStatus = async (checkId, status) => {
try {
const updatedCheck = await Check.findOneAndUpdate(
{ _id: checkId },
{ status },
{ new: true }
);
return updatedCheck;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "updateCheckStatus";
throw error;
}
};
/** /**
* Delete all checks for a monitor * Delete all checks for a monitor
* @async * @async
@@ -317,6 +342,7 @@ export {
createChecks, createChecks,
getChecksByMonitor, getChecksByMonitor,
getChecksByTeam, getChecksByTeam,
updateCheckStatus,
deleteChecks, deleteChecks,
deleteChecksByTeamId, deleteChecksByTeamId,
updateChecksTTL, updateChecksTTL,
+2
View File
@@ -20,6 +20,8 @@ class CheckRoutes {
this.router.get("/:monitorId", this.checkController.getChecksByMonitor); this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
this.router.put("/:checkId", this.checkController.updateCheckStatus);
this.router.post( this.router.post(
"/:monitorId", "/:monitorId",
verifyOwnership(Monitor, "monitorId"), verifyOwnership(Monitor, "monitorId"),
+5
View File
@@ -289,6 +289,10 @@ const createCheckBodyValidation = joi.object({
message: joi.string().required(), message: joi.string().required(),
}); });
const updateCheckStatusBodyValidation = joi.object({
status: joi.boolean(),
});
const getChecksParamValidation = joi.object({ const getChecksParamValidation = joi.object({
monitorId: joi.string().required(), monitorId: joi.string().required(),
}); });
@@ -662,6 +666,7 @@ export {
getChecksQueryValidation, getChecksQueryValidation,
getTeamChecksParamValidation, getTeamChecksParamValidation,
getTeamChecksQueryValidation, getTeamChecksQueryValidation,
updateCheckStatusBodyValidation,
deleteChecksParamValidation, deleteChecksParamValidation,
deleteChecksByTeamIdParamValidation, deleteChecksByTeamIdParamValidation,
updateChecksTTLBodyValidation, updateChecksTTLBodyValidation,