From afece4df650667c999313615e88af608bd3613d1 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 13 Jun 2025 10:46:06 +0800 Subject: [PATCH] update routes, validation --- client/src/Components/Dialog/index.jsx | 2 +- client/src/Components/StatBox/index.jsx | 4 ++-- .../Monitors/Components/MonitorsTable/index.jsx | 7 ++++--- client/src/Pages/Infrastructure/Monitors/index.jsx | 5 +---- client/src/Pages/PageSpeed/Monitors/index.jsx | 3 --- server/db/mongo/modules/monitorModule.js | 7 ++++--- server/routes/monitorRoute.js | 8 ++++---- server/validation/joi.js | 4 +--- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/client/src/Components/Dialog/index.jsx b/client/src/Components/Dialog/index.jsx index e07597df4..678eb8721 100644 --- a/client/src/Components/Dialog/index.jsx +++ b/client/src/Components/Dialog/index.jsx @@ -57,7 +57,7 @@ Dialog.propTypes = { onCancel: PropTypes.func.isRequired, confirmationButtonLabel: PropTypes.string.isRequired, onConfirm: PropTypes.func.isRequired, - isLoading: PropTypes.bool.isRequired, + isLoading: PropTypes.bool, }; export default Dialog; diff --git a/client/src/Components/StatBox/index.jsx b/client/src/Components/StatBox/index.jsx index 93fa46c2b..7d093de60 100644 --- a/client/src/Components/StatBox/index.jsx +++ b/client/src/Components/StatBox/index.jsx @@ -136,8 +136,8 @@ const StatBox = ({ }; StatBox.propTypes = { - heading: PropTypes.string.isRequired, - subHeading: PropTypes.node.isRequired, + heading: PropTypes.string, + subHeading: PropTypes.node, gradient: PropTypes.bool, status: PropTypes.string, sx: PropTypes.object, diff --git a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx index 761ecaa0e..7a5db231f 100644 --- a/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx +++ b/client/src/Pages/Infrastructure/Monitors/Components/MonitorsTable/index.jsx @@ -15,7 +15,7 @@ import { useNavigate } from "react-router-dom"; import PropTypes from "prop-types"; import { useTranslation } from "react-i18next"; -const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete }) => { +const MonitorsTable = ({ isLoading, monitors, isAdmin, handleActionMenuDelete }) => { // Utils const theme = useTheme(); const { t } = useTranslation(); @@ -86,6 +86,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete monitor={row} isAdmin={isAdmin} updateCallback={handleActionMenuDelete} + isLoading={isLoading} /> ), }, @@ -120,7 +121,7 @@ const MonitorsTable = ({ shouldRender, monitors, isAdmin, handleActionMenuDelete return ( { // Redux state - const { user } = useSelector((state) => state.auth); // Local state const [page, setPage] = useState(0); @@ -56,7 +54,6 @@ const InfrastructureMonitors = () => { const field = toFilterStatus !== undefined ? "status" : undefined; const [monitors, summary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 1, types: TYPES, page, @@ -118,7 +115,7 @@ const InfrastructureMonitors = () => { /> { const theme = useTheme(); const { t } = useTranslation(); const isAdmin = useIsAdmin(); - const { user } = useSelector((state) => state.auth); const [monitors, monitorsSummary, isLoading, networkError] = useFetchMonitorsByTeamId({ - teamId: user.teamId, limit: 10, types: TYPES, page: null, diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 3d9adab39..b6044f2c9 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -519,7 +519,8 @@ const getMonitorsByTeamId = async (req) => { order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const teamId = req.user.teamId; + const matchStage = { teamId: ObjectId.createFromHexString(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -560,7 +561,7 @@ const getMonitorsByTeamId = async (req) => { const getMonitorsAndSummaryByTeamId = async (req) => { try { const { type } = req.query; - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); const matchStage = { teamId }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; @@ -594,7 +595,7 @@ const getMonitorsWithChecksByTeamId = async (req) => { field = "name"; order = "asc"; } - const teamId = ObjectId.createFromHexString(req.params.teamId); + const teamId = ObjectId.createFromHexString(req.user.teamId); // Build match stage const matchStage = { teamId }; if (type !== undefined) { diff --git a/server/routes/monitorRoute.js b/server/routes/monitorRoute.js index 6d1db90ad..0dabab407 100755 --- a/server/routes/monitorRoute.js +++ b/server/routes/monitorRoute.js @@ -35,17 +35,17 @@ class MonitorRoutes { fetchMonitorCertificate ); }); + this.router.get("/team", this.monitorController.getMonitorsByTeamId); + this.router.get("/:monitorId", this.monitorController.getMonitorById); - this.router.get("/team/:teamId", this.monitorController.getMonitorsByTeamId); - this.router.get( - "/summary/team/:teamId", + "/summary/team", this.monitorController.getMonitorsAndSummaryByTeamId ); this.router.get( - "/team/:teamId/with-checks", + "/team/with-checks", this.monitorController.getMonitorsWithChecksByTeamId ); diff --git a/server/validation/joi.js b/server/validation/joi.js index 271cd2d21..aba7118d1 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -126,9 +126,7 @@ const getMonitorByIdQueryValidation = joi.object({ normalize: joi.boolean(), }); -const getMonitorsByTeamIdParamValidation = joi.object({ - teamId: joi.string().required(), -}); +const getMonitorsByTeamIdParamValidation = joi.object({}); const getMonitorsByTeamIdQueryValidation = joi.object({ limit: joi.number(),