Merge pull request #2446 from bluewave-labs/fix/remove-team-and-user-id

fix: remove team and user
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-06-13 13:35:36 +08:00
commit df69d06048
17 files changed
+31 -46

No files matched your search

+2 -2
View File
@@ -414,10 +414,10 @@ const useDeleteAllMonitors = () => {
const UseDeleteMonitorStats = () => { const UseDeleteMonitorStats = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const deleteMonitorStats = async ({ teamId }) => { const deleteMonitorStats = async () => {
setIsLoading(true); setIsLoading(true);
try { try {
const res = await networkService.deleteChecksByTeamId({ teamId }); await networkService.deleteChecksByTeamId();
createToast({ body: t("settingsStatsCleared") }); createToast({ body: t("settingsStatsCleared") });
} catch (error) { } catch (error) {
createToast({ body: t("settingsFailedToClearStats") }); createToast({ body: t("settingsFailedToClearStats") });
-1
View File
@@ -2,7 +2,6 @@ import { useState, useEffect, useCallback } from "react";
import { createToast } from "../Utils/toastUtils"; import { createToast } from "../Utils/toastUtils";
import { networkService } from "../main"; import { networkService } from "../main";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { NOTIFICATION_TYPES } from "../Pages/Notifications/utils"; import { NOTIFICATION_TYPES } from "../Pages/Notifications/utils";
+1 -1
View File
@@ -29,7 +29,7 @@ const Incidents = () => {
//Utils //Utils
const theme = useTheme(); const theme = useTheme();
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId(); const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId({});
useEffect(() => { useEffect(() => {
const monitorLookup = monitors?.reduce((acc, monitor) => { const monitorLookup = monitors?.reduce((acc, monitor) => {
@@ -186,8 +186,6 @@ const CreateInfrastructureMonitor = () => {
...(isCreate ? {} : { _id: monitorId }), ...(isCreate ? {} : { _id: monitorId }),
...rest, ...rest,
description: form.name, description: form.name,
teamId: user.teamId,
userId: user._id,
type: "hardware", type: "hardware",
notifications: infrastructureMonitor.notifications, notifications: infrastructureMonitor.notifications,
thresholds, thresholds,
@@ -48,8 +48,6 @@ const CreateNotifications = () => {
// local state // local state
const [notification, setNotification] = useState({ const [notification, setNotification] = useState({
userId: user._id,
teamId: user.teamId,
notificationName: "", notificationName: "",
address: "", address: "",
type: NOTIFICATION_TYPES[0]._id, type: NOTIFICATION_TYPES[0]._id,
@@ -86,8 +86,6 @@ const CreatePageSpeed = () => {
form = { form = {
...form, ...form,
description: form.name, description: form.name,
teamId: user.teamId,
userId: user._id,
notifications: monitor.notifications, notifications: monitor.notifications,
}; };
+1 -1
View File
@@ -96,7 +96,7 @@ const Settings = () => {
} }
if (name === "deleteStats") { if (name === "deleteStats") {
await deleteMonitorStats({ teamId: user.teamId }); await deleteMonitorStats();
return; return;
} }
@@ -1,17 +1,14 @@
import { useState } from "react"; import { useState } from "react";
import { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { useSelector } from "react-redux";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const useCreateStatusPage = (isCreate, url) => { const useCreateStatusPage = (isCreate, url) => {
const { user } = useSelector((state) => state.auth);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [networkError, setNetworkError] = useState(false); const [networkError, setNetworkError] = useState(false);
const createStatusPage = async ({ form }) => { const createStatusPage = async ({ form }) => {
setIsLoading(true); setIsLoading(true);
try { try {
await networkService.createStatusPage({ user, form, isCreate, url }); await networkService.createStatusPage({ form, isCreate, url });
return true; return true;
} catch (error) { } catch (error) {
setNetworkError(true); setNetworkError(true);
@@ -13,9 +13,7 @@ const useStatusPagesFetch = () => {
useEffect(() => { useEffect(() => {
const fetchStatusPages = async () => { const fetchStatusPages = async () => {
try { try {
const res = await networkService.getStatusPagesByTeamId({ const res = await networkService.getStatusPagesByTeamId();
teamId: user.teamId,
});
setStatusPages(res?.data?.data); setStatusPages(res?.data?.data);
} catch (error) { } catch (error) {
setNetworkError(true); setNetworkError(true);
-6
View File
@@ -18,7 +18,6 @@ import Checkbox from "../../../Components/Inputs/Checkbox";
// Utils // Utils
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useState } from "react"; import { useState } from "react";
import { useSelector } from "react-redux";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { monitorValidation } from "../../../Validation/validation"; import { monitorValidation } from "../../../Validation/validation";
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
@@ -26,9 +25,6 @@ import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications";
import { useCreateMonitor } from "../../../Hooks/monitorHooks"; import { useCreateMonitor } from "../../../Hooks/monitorHooks";
const CreateMonitor = () => { const CreateMonitor = () => {
// Redux state
const { user } = useSelector((state) => state.auth);
// Local state // Local state
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const [https, setHttps] = useState(true); const [https, setHttps] = useState(true);
@@ -143,8 +139,6 @@ const CreateMonitor = () => {
form = { form = {
...form, ...form,
description: monitor.name || monitor.url, description: monitor.name || monitor.url,
teamId: user.teamId,
userId: user._id,
notifications: monitor.notifications, notifications: monitor.notifications,
}; };
+2 -5
View File
@@ -838,8 +838,7 @@ class NetworkService {
} }
async getStatusPagesByTeamId(config) { async getStatusPagesByTeamId(config) {
const { teamId } = config; return this.axiosInstance.get(`/status-page/team`, {
return this.axiosInstance.get(`/status-page/team/${teamId}`, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
@@ -847,11 +846,9 @@ class NetworkService {
} }
async createStatusPage(config) { async createStatusPage(config) {
const { user, form, isCreate } = config; const { form, isCreate } = config;
const fd = new FormData(); const fd = new FormData();
fd.append("teamId", user.teamId);
fd.append("userId", user._id);
fd.append("type", form.type); fd.append("type", form.type);
form.isPublished !== undefined && fd.append("isPublished", form.isPublished); form.isPublished !== undefined && fd.append("isPublished", form.isPublished);
form.companyName && fd.append("companyName", form.companyName); form.companyName && fd.append("companyName", form.companyName);
+6 -1
View File
@@ -238,7 +238,12 @@ class MonitorController {
} }
try { try {
const monitor = await this.db.createMonitor(req.body); const { _id, teamId } = req.user;
const monitor = await this.db.createMonitor({
body: req.body,
teamId,
userId: _id,
});
// Add monitor to job queue // Add monitor to job queue
this.jobQueue.addJob(monitor._id, monitor); this.jobQueue.addJob(monitor._id, monitor);
+8 -2
View File
@@ -24,7 +24,13 @@ class StatusPageController {
} }
try { try {
const statusPage = await this.db.createStatusPage(req.body, req.file); const { _id, teamId } = req.user;
const statusPage = await this.db.createStatusPage({
statusPageData: req.body,
image: req.file,
userId: _id,
teamId,
});
return res.success({ return res.success({
msg: this.stringService.statusPageCreate, msg: this.stringService.statusPageCreate,
data: statusPage, data: statusPage,
@@ -93,7 +99,7 @@ class StatusPageController {
getStatusPagesByTeamId = async (req, res, next) => { getStatusPagesByTeamId = async (req, res, next) => {
try { try {
const teamId = req.params.teamId; const teamId = req.user.teamId;
const statusPages = await this.db.getStatusPagesByTeamId(teamId); const statusPages = await this.db.getStatusPagesByTeamId(teamId);
return res.success({ return res.success({
+2 -2
View File
@@ -665,9 +665,9 @@ const getMonitorsWithChecksByTeamId = async ({
* @returns {Promise<Monitor>} * @returns {Promise<Monitor>}
* @throws {Error} * @throws {Error}
*/ */
const createMonitor = async (body) => { const createMonitor = async ({ body, teamId, userId }) => {
try { try {
const monitor = new Monitor({ ...body }); const monitor = new Monitor({ ...body, teamId, userId });
const saved = await monitor.save(); const saved = await monitor.save();
return saved; return saved;
} catch (error) { } catch (error) {
+6 -3
View File
@@ -1,16 +1,19 @@
import StatusPage from "../../models/StatusPage.js"; import StatusPage from "../../models/StatusPage.js";
import Monitor from "../../models/Monitor.js";
import { NormalizeData } from "../../../utils/dataUtils.js"; import { NormalizeData } from "../../../utils/dataUtils.js";
import ServiceRegistry from "../../../service/serviceRegistry.js"; import ServiceRegistry from "../../../service/serviceRegistry.js";
import StringService from "../../../service/stringService.js"; import StringService from "../../../service/stringService.js";
const SERVICE_NAME = "statusPageModule"; const SERVICE_NAME = "statusPageModule";
const createStatusPage = async (statusPageData, image) => { const createStatusPage = async ({ statusPageData, image, userId, teamId }) => {
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME); const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
try { try {
const statusPage = new StatusPage({ ...statusPageData }); const statusPage = new StatusPage({
...statusPageData,
userId,
teamId,
});
if (image) { if (image) {
statusPage.logo = { statusPage.logo = {
data: image.buffer, data: image.buffer,
+1 -5
View File
@@ -12,11 +12,7 @@ class StatusPageRoutes {
initRoutes() { initRoutes() {
this.router.get("/", this.statusPageController.getStatusPage); this.router.get("/", this.statusPageController.getStatusPage);
this.router.get( this.router.get("/team", verifyJWT, this.statusPageController.getStatusPagesByTeamId);
"/team/:teamId",
verifyJWT,
this.statusPageController.getStatusPagesByTeamId
);
this.router.get("/:url", this.statusPageController.getStatusPageByUrl); this.router.get("/:url", this.statusPageController.getStatusPageByUrl);
this.router.post( this.router.post(
-4
View File
@@ -165,8 +165,6 @@ const getCertificateParamValidation = joi.object({
const createMonitorBodyValidation = joi.object({ const createMonitorBodyValidation = joi.object({
_id: joi.string(), _id: joi.string(),
userId: joi.string().required(),
teamId: joi.string().required(),
name: joi.string().required(), name: joi.string().required(),
description: joi.string().required(), description: joi.string().required(),
type: joi.string().required(), type: joi.string().required(),
@@ -424,8 +422,6 @@ const getStatusPageQueryValidation = joi.object({
}); });
const createStatusPageBodyValidation = joi.object({ const createStatusPageBodyValidation = joi.object({
userId: joi.string().required(),
teamId: joi.string().required(),
type: joi.string().valid("uptime").required(), type: joi.string().valid("uptime").required(),
companyName: joi.string().required(), companyName: joi.string().required(),
url: joi url: joi