Merge pull request #2445 from bluewave-labs/fix/checks-team-id
fix: checks team
This commit is contained in:
7 files changed
+58
-36
No files matched your search
@@ -24,7 +24,6 @@ const IncidentTable = ({
|
|||||||
}) => {
|
}) => {
|
||||||
//Redux state
|
//Redux state
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
|
|
||||||
//Local state
|
//Local state
|
||||||
const [teamId, setTeamId] = useState(undefined);
|
const [teamId, setTeamId] = useState(undefined);
|
||||||
@@ -61,13 +60,13 @@ const IncidentTable = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedMonitor === "0") {
|
if (selectedMonitor === "0") {
|
||||||
setTeamId(user.teamId);
|
setTeamId("placeholder"); // TODO this isn't needed any longer, fix hook
|
||||||
setMonitorId(undefined);
|
setMonitorId(undefined);
|
||||||
} else {
|
} else {
|
||||||
setMonitorId(selectedMonitor);
|
setMonitorId(selectedMonitor);
|
||||||
setTeamId(undefined);
|
setTeamId(undefined);
|
||||||
}
|
}
|
||||||
}, [selectedMonitor, user.teamId]);
|
}, [selectedMonitor]);
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import OptionsHeader from "./Components/OptionsHeader";
|
|||||||
//Utils
|
//Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useFetchMonitorsByTeamId } from "../../Hooks/monitorHooks";
|
import { useFetchMonitorsByTeamId } from "../../Hooks/monitorHooks";
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import NetworkError from "../../Components/GenericFallback/NetworkError";
|
import NetworkError from "../../Components/GenericFallback/NetworkError";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -16,7 +15,6 @@ import { useTranslation } from "react-i18next";
|
|||||||
//Constants
|
//Constants
|
||||||
const Incidents = () => {
|
const Incidents = () => {
|
||||||
// Redux state
|
// Redux state
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const BREADCRUMBS = [
|
const BREADCRUMBS = [
|
||||||
@@ -31,9 +29,7 @@ const Incidents = () => {
|
|||||||
|
|
||||||
//Utils
|
//Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId({
|
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId();
|
||||||
teamId: user.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const monitorLookup = monitors?.reduce((acc, monitor) => {
|
const monitorLookup = monitors?.reduce((acc, monitor) => {
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ class NetworkService {
|
|||||||
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
|
* @returns {Promise<AxiosResponse>} The response from the axios DELETE request.
|
||||||
*/
|
*/
|
||||||
async deleteChecksByTeamId(config) {
|
async deleteChecksByTeamId(config) {
|
||||||
return this.axiosInstance.delete(`/checks/team/${config.teamId}`, {
|
return this.axiosInstance.delete(`/checks/team`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
@@ -595,7 +595,7 @@ class NetworkService {
|
|||||||
if (config.page) params.append("page", config.page);
|
if (config.page) params.append("page", config.page);
|
||||||
if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage);
|
if (config.rowsPerPage) params.append("rowsPerPage", config.rowsPerPage);
|
||||||
if (config.status !== undefined) params.append("status", config.status);
|
if (config.status !== undefined) params.append("status", config.status);
|
||||||
return this.axiosInstance.get(`/checks/team/${config.teamId}?${params.toString()}`);
|
return this.axiosInstance.get(`/checks/team?${params.toString()}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -54,7 +54,18 @@ class CheckController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await this.db.getChecksByMonitor(req);
|
const { monitorId } = req.params;
|
||||||
|
let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
|
||||||
|
const result = await this.db.getChecksByMonitor({
|
||||||
|
monitorId,
|
||||||
|
type,
|
||||||
|
sortOrder,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
status,
|
||||||
|
});
|
||||||
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.checkGet,
|
msg: this.stringService.checkGet,
|
||||||
@@ -74,8 +85,17 @@ class CheckController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const checkData = await this.db.getChecksByTeam(req);
|
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
|
||||||
|
const { teamId } = req.user;
|
||||||
|
|
||||||
|
const checkData = await this.db.getChecksByTeam({
|
||||||
|
sortOrder,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
teamId,
|
||||||
|
});
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.checkGet,
|
msg: this.stringService.checkGet,
|
||||||
data: checkData,
|
data: checkData,
|
||||||
@@ -114,7 +134,8 @@ class CheckController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const deletedCount = await this.db.deleteChecksByTeamId(req.params.teamId);
|
const { teamId } = req.user;
|
||||||
|
const deletedCount = await this.db.deleteChecksByTeamId(teamId);
|
||||||
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.checkDelete,
|
msg: this.stringService.checkDelete,
|
||||||
@@ -137,9 +158,7 @@ class CheckController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Get user's teamId
|
// Get user's teamId
|
||||||
const token = getTokenFromHeaders(req.headers);
|
const { teamId } = req.user;
|
||||||
const { jwtSecret } = this.settingsService.getSettings();
|
|
||||||
const { teamId } = jwt.verify(token, jwtSecret);
|
|
||||||
const ttl = parseInt(req.body.ttl, 10) * SECONDS_PER_DAY;
|
const ttl = parseInt(req.body.ttl, 10) * SECONDS_PER_DAY;
|
||||||
await this.db.updateChecksTTL(teamId, ttl);
|
await this.db.updateChecksTTL(teamId, ttl);
|
||||||
|
|
||||||
|
|||||||
@@ -57,10 +57,17 @@ const createChecks = async (checks) => {
|
|||||||
* @returns {Promise<Array<Check>>}
|
* @returns {Promise<Array<Check>>}
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
const getChecksByMonitor = async (req) => {
|
const getChecksByMonitor = async ({
|
||||||
|
monitorId,
|
||||||
|
type,
|
||||||
|
sortOrder,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
status,
|
||||||
|
}) => {
|
||||||
try {
|
try {
|
||||||
const { monitorId } = req.params;
|
|
||||||
let { type, sortOrder, dateRange, filter, page, rowsPerPage, status } = req.query;
|
|
||||||
status = typeof status !== "undefined" ? false : undefined;
|
status = typeof status !== "undefined" ? false : undefined;
|
||||||
page = parseInt(page);
|
page = parseInt(page);
|
||||||
rowsPerPage = parseInt(rowsPerPage);
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
@@ -142,12 +149,17 @@ const getChecksByMonitor = async (req) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getChecksByTeam = async (req) => {
|
const getChecksByTeam = async ({
|
||||||
|
sortOrder,
|
||||||
|
dateRange,
|
||||||
|
filter,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
teamId,
|
||||||
|
}) => {
|
||||||
try {
|
try {
|
||||||
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
|
|
||||||
page = parseInt(page);
|
page = parseInt(page);
|
||||||
rowsPerPage = parseInt(rowsPerPage);
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
const { teamId } = req.params;
|
|
||||||
const matchStage = {
|
const matchStage = {
|
||||||
teamId: ObjectId.createFromHexString(teamId),
|
teamId: ObjectId.createFromHexString(teamId),
|
||||||
status: false,
|
status: false,
|
||||||
|
|||||||
@@ -11,7 +11,15 @@ class CheckRoutes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initRoutes() {
|
initRoutes() {
|
||||||
|
this.router.get("/team", this.checkController.getChecksByTeam);
|
||||||
|
this.router.delete(
|
||||||
|
"/team",
|
||||||
|
isAllowed(["admin", "superadmin"]),
|
||||||
|
this.checkController.deleteChecksByTeamId
|
||||||
|
);
|
||||||
|
|
||||||
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
||||||
|
|
||||||
this.router.post(
|
this.router.post(
|
||||||
"/:monitorId",
|
"/:monitorId",
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
verifyOwnership(Monitor, "monitorId"),
|
||||||
@@ -23,14 +31,6 @@ class CheckRoutes {
|
|||||||
this.checkController.deleteChecks
|
this.checkController.deleteChecks
|
||||||
);
|
);
|
||||||
|
|
||||||
this.router.get("/team/:teamId", this.checkController.getChecksByTeam);
|
|
||||||
|
|
||||||
this.router.delete(
|
|
||||||
"/team/:teamId",
|
|
||||||
isAllowed(["admin", "superadmin"]),
|
|
||||||
this.checkController.deleteChecksByTeamId
|
|
||||||
);
|
|
||||||
|
|
||||||
this.router.put(
|
this.router.put(
|
||||||
"/team/ttl",
|
"/team/ttl",
|
||||||
isAllowed(["admin", "superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
|
|||||||
@@ -301,9 +301,7 @@ const getChecksQueryValidation = joi.object({
|
|||||||
status: joi.boolean(),
|
status: joi.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getTeamChecksParamValidation = joi.object({
|
const getTeamChecksParamValidation = joi.object({});
|
||||||
teamId: joi.string().required(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const getTeamChecksQueryValidation = joi.object({
|
const getTeamChecksQueryValidation = joi.object({
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
@@ -319,9 +317,7 @@ const deleteChecksParamValidation = joi.object({
|
|||||||
monitorId: joi.string().required(),
|
monitorId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const deleteChecksByTeamIdParamValidation = joi.object({
|
const deleteChecksByTeamIdParamValidation = joi.object({});
|
||||||
teamId: joi.string().required(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateChecksTTLBodyValidation = joi.object({
|
const updateChecksTTLBodyValidation = joi.object({
|
||||||
ttl: joi.number().required(),
|
ttl: joi.number().required(),
|
||||||
|
|||||||
Reference in new issue
Block a user