VerifyTemAccess Middleware

This commit is contained in:
Br0wnHammer committed 2025-06-25 11:52:38 +05:30
1 parent 95b832c1c6
commit 78a2e5d106
4 files changed
+17 -15

No files matched your search

+6 -6
View File
@@ -8,9 +8,9 @@ import {
deleteChecksParamValidation,
deleteChecksByTeamIdParamValidation,
updateChecksTTLBodyValidation,
updateCheckStatusBodyValidation,
updateAllChecksStatusBodyValidation,
updateCheckStatusParamValidation,
ackCheckBodyValidation,
ackAllChecksParamValidation,
ackAllChecksBodyValidation,
} from "../validation/joi.js";
import jwt from "jsonwebtoken";
import { getTokenFromHeaders } from "../utils/utils.js";
@@ -114,7 +114,7 @@ class CheckController {
ackCheck = async (req, res, next) => {
try {
await updateCheckStatusBodyValidation.validateAsync(req.body);
await ackCheckBodyValidation.validateAsync(req.body);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
@@ -138,8 +138,8 @@ class CheckController {
ackAllChecks = async (req, res, next) => {
try {
await updateCheckStatusParamValidation.validateAsync(req.params);
await updateAllChecksStatusBodyValidation.validateAsync(req.body);
await ackAllChecksParamValidation.validateAsync(req.params);
await ackAllChecksBodyValidation.validateAsync(req.body);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
+2 -2
View File
@@ -76,7 +76,7 @@ const getChecksByMonitor = async ({
const matchStage = {
monitorId: ObjectId.createFromHexString(monitorId),
...(typeof status !== "undefined" && { status }),
...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }),
...(typeof ack !== "undefined" && { ack: ack === "true" }),
...(dateRangeLookup[dateRange] && {
createdAt: {
$gte: dateRangeLookup[dateRange],
@@ -168,7 +168,7 @@ const getChecksByTeam = async ({
const matchStage = {
teamId: ObjectId.createFromHexString(teamId),
status: status,
...(typeof ack !== "undefined" && { ack: ack === "true" ? true : false }),
...(typeof ack !== "undefined" && { ack: ack === "true" }),
...(dateRangeLookup[dateRange] && {
createdAt: {
$gte: dateRangeLookup[dateRange],
+3 -1
View File
@@ -1,7 +1,9 @@
import { Router } from "express";
import { verifyOwnership } from "../middleware/verifyOwnership.js";
import { verifyTeamAccess } from "../middleware/verifyTeamAccess.js";
import { isAllowed } from "../middleware/isAllowed.js";
import Monitor from "../db/models/Monitor.js";
import Check from "../db/models/Check.js";
class CheckRoutes {
constructor(checkController) {
@@ -20,7 +22,7 @@ class CheckRoutes {
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
this.router.put("/:checkId", this.checkController.ackCheck);
this.router.put("/:checkId", verifyTeamAccess(Check, "checkId"), this.checkController.ackCheck);
this.router.put("/:path/:monitorId?", this.checkController.ackAllChecks);
+6 -6
View File
@@ -289,16 +289,16 @@ const createCheckBodyValidation = joi.object({
message: joi.string().required(),
});
const updateCheckStatusBodyValidation = joi.object({
const ackCheckBodyValidation = joi.object({
ack: joi.boolean(),
});
const updateCheckStatusParamValidation = joi.object({
const ackAllChecksParamValidation = joi.object({
monitorId: joi.string().optional(),
path: joi.string().valid("monitor", "team").required(),
});
const updateAllChecksStatusBodyValidation = joi.object({
const ackAllChecksBodyValidation = joi.object({
ack: joi.boolean(),
});
@@ -669,9 +669,9 @@ export {
getChecksQueryValidation,
getTeamChecksParamValidation,
getTeamChecksQueryValidation,
updateCheckStatusBodyValidation,
updateAllChecksStatusBodyValidation,
updateCheckStatusParamValidation,
ackCheckBodyValidation,
ackAllChecksParamValidation,
ackAllChecksBodyValidation,
deleteChecksParamValidation,
deleteChecksByTeamIdParamValidation,
updateChecksTTLBodyValidation,