mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-21 17:19:42 -06:00
Route for Updating a single Incident Status
This commit is contained in:
@@ -42,7 +42,7 @@ const IncidentTable = ({
|
||||
sortOrder: "desc",
|
||||
limit: null,
|
||||
dateRange,
|
||||
filter: filter === "resolved" ? "resolve" : filter,
|
||||
filter: filter === "resolved" ? "all" : filter,
|
||||
page: page,
|
||||
rowsPerPage: rowsPerPage,
|
||||
enabled: selectedMonitor !== "0",
|
||||
@@ -54,7 +54,7 @@ const IncidentTable = ({
|
||||
sortOrder: "desc",
|
||||
limit: null,
|
||||
dateRange,
|
||||
filter: filter === "resolved" ? "resolve" : filter,
|
||||
filter: filter === "resolved" ? "all" : filter,
|
||||
page: page,
|
||||
rowsPerPage: rowsPerPage,
|
||||
enabled: selectedMonitor === "0",
|
||||
|
||||
@@ -598,6 +598,24 @@ class NetworkService {
|
||||
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
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
updateChecksTTLBodyValidation,
|
||||
updateCheckStatusBodyValidation,
|
||||
} from "../validation/joi.js";
|
||||
import jwt from "jsonwebtoken";
|
||||
import { getTokenFromHeaders } from "../utils/utils.js";
|
||||
@@ -85,7 +86,7 @@ class CheckController {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
|
||||
let { sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
|
||||
const { teamId } = req.user;
|
||||
|
||||
const checkData = await this.db.getChecksByTeam({
|
||||
@@ -95,6 +96,7 @@ class CheckController {
|
||||
page,
|
||||
rowsPerPage,
|
||||
teamId,
|
||||
status,
|
||||
});
|
||||
return res.success({
|
||||
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) => {
|
||||
try {
|
||||
await deleteChecksParamValidation.validateAsync(req.params);
|
||||
|
||||
@@ -68,7 +68,7 @@ const getChecksByMonitor = async ({
|
||||
status,
|
||||
}) => {
|
||||
try {
|
||||
status = typeof status !== "undefined" ? false : undefined;
|
||||
status = status === "true" ? true : status === "false" ? false : undefined;
|
||||
page = parseInt(page);
|
||||
rowsPerPage = parseInt(rowsPerPage);
|
||||
// Match
|
||||
@@ -156,13 +156,15 @@ const getChecksByTeam = async ({
|
||||
page,
|
||||
rowsPerPage,
|
||||
teamId,
|
||||
status,
|
||||
}) => {
|
||||
try {
|
||||
status = status === "true" ? true : false;
|
||||
page = parseInt(page);
|
||||
rowsPerPage = parseInt(rowsPerPage);
|
||||
const matchStage = {
|
||||
teamId: ObjectId.createFromHexString(teamId),
|
||||
status: false,
|
||||
status: status,
|
||||
...(dateRangeLookup[dateRange] && {
|
||||
createdAt: {
|
||||
$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
|
||||
* @async
|
||||
@@ -317,6 +342,7 @@ export {
|
||||
createChecks,
|
||||
getChecksByMonitor,
|
||||
getChecksByTeam,
|
||||
updateCheckStatus,
|
||||
deleteChecks,
|
||||
deleteChecksByTeamId,
|
||||
updateChecksTTL,
|
||||
|
||||
@@ -20,6 +20,8 @@ class CheckRoutes {
|
||||
|
||||
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
||||
|
||||
this.router.put("/:checkId", this.checkController.updateCheckStatus);
|
||||
|
||||
this.router.post(
|
||||
"/:monitorId",
|
||||
verifyOwnership(Monitor, "monitorId"),
|
||||
|
||||
@@ -289,6 +289,10 @@ const createCheckBodyValidation = joi.object({
|
||||
message: joi.string().required(),
|
||||
});
|
||||
|
||||
const updateCheckStatusBodyValidation = joi.object({
|
||||
status: joi.boolean(),
|
||||
});
|
||||
|
||||
const getChecksParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
@@ -662,6 +666,7 @@ export {
|
||||
getChecksQueryValidation,
|
||||
getTeamChecksParamValidation,
|
||||
getTeamChecksQueryValidation,
|
||||
updateCheckStatusBodyValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
updateChecksTTLBodyValidation,
|
||||
|
||||
Reference in New Issue
Block a user