check details base

This commit is contained in:
Alex Holliday committed 2025-12-19 15:12:30 -08:00
1 parent d139e0b643
commit 66c406151a
9 files changed
+112 -47

No files matched your search

@@ -4,6 +4,7 @@ import { CheckService } from "@/services/index.js";
export interface IChecksController {
getChecksByStatus: (req: Request, res: Response, next: NextFunction) => void;
getCheckById: (req: Request, res: Response, next: NextFunction) => void;
}
class ChecksController implements IChecksController {
@@ -53,6 +54,30 @@ class ChecksController implements IChecksController {
next(error);
}
};
getCheckById = async (req: Request, res: Response, next: NextFunction) => {
try {
const userContext = req.user;
if (!userContext) {
return res.status(401).json({ message: "Unauthorized" });
}
const teamId = userContext.currentTeamId;
if (!teamId) {
throw new ApiError("No team ID", 400);
}
const checkId = req.params.id;
const check = await this.checkService.getCheckById(checkId, teamId);
return res.status(200).json({
message: "Check retrieved successfully",
data: check,
});
} catch (error) {
next(error);
}
};
}
export default ChecksController;
+7
View File
@@ -26,6 +26,13 @@ class CheckRoutes {
validateQuery(checksStatusIdQuerySchema),
this.controller.getChecksByStatus
);
this.router.get(
"/:id",
verifyToken,
addUserContext,
verifyOrgPermission([PERMISSIONS.checks.read]),
this.controller.getCheckById
);
};
getRouter() {
@@ -33,6 +33,8 @@ export interface ICheckService {
range: string
) => Promise<{ checks: ICheck[]; count: number }>;
getCheckById: (checkId: string, teamId: string) => Promise<ICheck | null>;
cleanupOrphanedChecks: () => Promise<boolean>;
}
@@ -259,6 +261,13 @@ class CheckService implements ICheckService {
]);
return { checks, count };
};
getCheckById = async (checkId: string, teamId: string) => {
return await Check.findOne({
_id: new mongoose.Types.ObjectId(checkId),
"metadata.teamId": new mongoose.Types.ObjectId(teamId),
});
};
}
export default CheckService;