Add route, controller, and DB methods for fetching maintenance window by ID
This commit is contained in:
1 parent
114cfd6cb7
commit
e3c0944062
10 files changed
+143
-16
No files matched your search
+1
-1
@@ -110,7 +110,7 @@ function App() {
|
||||
element={<ProtectedRoute Component={MaintenanceWithAdminProp} />}
|
||||
/>
|
||||
<Route
|
||||
path="/maintenance/create"
|
||||
path="/maintenance/create/:maintenanceWindowId?"
|
||||
element={<CreateNewMaintenanceWindow />}
|
||||
/>
|
||||
<Route
|
||||
|
||||
@@ -8,6 +8,7 @@ import { LocalizationProvider } from "@mui/x-date-pickers";
|
||||
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
||||
import { MobileTimePicker } from "@mui/x-date-pickers/MobileTimePicker";
|
||||
import { maintenanceWindowValidation } from "../../../Validation/validation";
|
||||
import { createToast } from "../../../Utils/toastUtils";
|
||||
import dayjs from "dayjs";
|
||||
import Select from "../../../Components/Inputs/Select";
|
||||
import Field from "../../../Components/Inputs/Field";
|
||||
@@ -16,14 +17,14 @@ import CalendarIcon from "../../../assets/icons/calendar.svg?react";
|
||||
import "./index.css";
|
||||
import Search from "../../../Components/Inputs/Search";
|
||||
import { networkService } from "../../../main";
|
||||
import { logger } from "../../../Utils/Logger";
|
||||
import {
|
||||
MS_PER_SECOND,
|
||||
MS_PER_MINUTE,
|
||||
MS_PER_HOUR,
|
||||
MS_PER_DAY,
|
||||
} from "../../../Utils/timeUtils";
|
||||
import { createToast } from "../../../Utils/toastUtils";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
|
||||
const MS_LOOKUP = {
|
||||
seconds: MS_PER_SECOND,
|
||||
@@ -75,11 +76,13 @@ const getIdByValue = (config, name) => {
|
||||
};
|
||||
|
||||
const CreateMaintenance = () => {
|
||||
const { maintenanceWindowId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const theme = useTheme();
|
||||
const { user, authToken } = useSelector((state) => state.auth);
|
||||
const [monitors, setMonitors] = useState([]);
|
||||
const [search, setSearch] = useState("");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [form, setForm] = useState({
|
||||
repeat: "none",
|
||||
startDate: dayjs(),
|
||||
@@ -93,13 +96,48 @@ const CreateMaintenance = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const fetchMonitors = async () => {
|
||||
const response = await networkService.getMonitorsByTeamId({
|
||||
authToken: authToken,
|
||||
teamId: user.teamId,
|
||||
limit: -1,
|
||||
types: ["http", "ping", "pagespeed"],
|
||||
});
|
||||
setMonitors(response.data.data.monitors);
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const response = await networkService.getMonitorsByTeamId({
|
||||
authToken: authToken,
|
||||
teamId: user.teamId,
|
||||
limit: -1,
|
||||
types: ["http", "ping", "pagespeed"],
|
||||
});
|
||||
setMonitors(response.data.data.monitors);
|
||||
|
||||
if (maintenanceWindowId === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const maintenanceWindow = await networkService.getMaintenanceWindowById(
|
||||
{
|
||||
authToken: authToken,
|
||||
maintenanceWindowId: maintenanceWindowId,
|
||||
}
|
||||
);
|
||||
logger.info(maintenanceWindow);
|
||||
// const { name, start, end, repeat, monitors } =
|
||||
// maintenanceWindow.data.data.maintenanceWindow;
|
||||
// const startDate = dayjs(start);
|
||||
// const startTime = dayjs(start);
|
||||
// const duration = dayjs(end).diff(dayjs(start), "seconds");
|
||||
// const durationUnit = "seconds";
|
||||
// setForm({
|
||||
// name,
|
||||
// startDate,
|
||||
// startTime,
|
||||
// duration,
|
||||
// durationUnit,
|
||||
// repeat,
|
||||
// monitors,
|
||||
// });
|
||||
} catch (error) {
|
||||
createToast({ body: "Failed to fetch data" });
|
||||
logger.error("Failed to fetch monitors", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
fetchMonitors();
|
||||
}, [authToken, user]);
|
||||
@@ -190,7 +228,6 @@ const CreateMaintenance = () => {
|
||||
repeat,
|
||||
};
|
||||
|
||||
console.log(submit);
|
||||
if (repeat === 0) {
|
||||
submit.expiry = end;
|
||||
}
|
||||
|
||||
@@ -14,25 +14,34 @@ class Logger {
|
||||
const NO_OP = () => {};
|
||||
|
||||
if (logLevel === "none") {
|
||||
this.info = NO_OP;
|
||||
this.error = NO_OP;
|
||||
this.warn = NO_OP;
|
||||
this.log = NO_OP;
|
||||
return;
|
||||
}
|
||||
|
||||
this.error = console.error.bind(console);
|
||||
|
||||
if (logLevel === "error") {
|
||||
this.info = NO_OP;
|
||||
this.warn = NO_OP;
|
||||
this.log = NO_OP;
|
||||
return;
|
||||
}
|
||||
this.warn = console.warn.bind(console);
|
||||
|
||||
if (logLevel === "warn") {
|
||||
this.info = NO_OP;
|
||||
this.log = NO_OP;
|
||||
return;
|
||||
}
|
||||
|
||||
if (logLevel === "info") {
|
||||
this.log = NO_OP;
|
||||
return;
|
||||
}
|
||||
|
||||
this.error = console.error.bind(console);
|
||||
this.warn = console.warn.bind(console);
|
||||
this.info = console.info.bind(console);
|
||||
this.log = console.log.bind(console);
|
||||
}
|
||||
|
||||
|
||||
@@ -716,6 +716,33 @@ class NetworkService {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* Get maintenance window by id
|
||||
* ************************************
|
||||
*
|
||||
* @async
|
||||
* @param {Object} config - The configuration object.
|
||||
* @param {string} config.authToken - The authorization token to be used in the request header.
|
||||
* @param {string} [config.maintenanceWindowId] - The id of the maintenance window to delete.
|
||||
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
||||
*
|
||||
*/
|
||||
|
||||
async getMaintenanceWindowById(config) {
|
||||
const { authToken, maintenanceWindowId } = config;
|
||||
return this.axiosInstance.get(
|
||||
`/maintenance-window/${maintenanceWindowId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* Get maintenance windows by teamId
|
||||
@@ -735,7 +762,6 @@ class NetworkService {
|
||||
|
||||
async getMaintenanceWindowsByTeamId(config) {
|
||||
const { authToken, active, page, rowsPerPage, field, order } = config;
|
||||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (active) params.append("status", active);
|
||||
@@ -756,7 +782,7 @@ class NetworkService {
|
||||
}
|
||||
/**
|
||||
* ************************************
|
||||
* Get maintenance windows by teamId
|
||||
* Delete maintenance window by id
|
||||
* ************************************
|
||||
*
|
||||
* @async
|
||||
|
||||
Reference in new issue
Block a user