From aed4881eac1068b13c43a1085c4303d2e1d72e7b Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 2 Aug 2024 11:54:46 -0700 Subject: [PATCH] Fix rest verbs --- Client/src/Features/Auth/authSlice.js | 6 ++---- .../UptimeMonitors/uptimeMonitorsSlice.js | 20 ++++++++----------- Server/routes/authRoute.js | 2 +- Server/routes/monitorRoute.js | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index 2b75c8d33..a30c295d9 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -61,7 +61,7 @@ export const update = createAsyncThunk( form.deleteProfileImage && fd.append("deleteProfileImage", form.deleteProfileImage); - const res = await axiosInstance.post(`/auth/user/${user._id}`, fd, { + const res = await axiosInstance.put(`/auth/user/${user._id}`, fd, { headers: { Authorization: `Bearer ${token}`, "Content-Type": "multipart/form-data", @@ -185,9 +185,7 @@ const handleForgotRejected = (state, action) => { const handleNewPasswordRejected = (state, action) => { state.isLoading = false; state.success = false; - state.msg = action.payload - ? action.payload.msg - : "Failed to reset password."; + state.msg = action.payload ? action.payload.msg : "Failed to reset password."; }; const authSlice = createSlice({ diff --git a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js index 05c182f5f..52a02cd55 100644 --- a/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js +++ b/Client/src/Features/UptimeMonitors/uptimeMonitorsSlice.js @@ -77,9 +77,9 @@ export const updateUptimeMonitor = createAsyncThunk( name: monitor.name, description: monitor.description, interval: monitor.interval, - notifications: monitor.notifications + notifications: monitor.notifications, }; - const res = await axiosInstance.post( + const res = await axiosInstance.put( `/monitors/edit/${monitor._id}`, updatedFields, { @@ -104,16 +104,12 @@ export const deleteUptimeMonitor = createAsyncThunk( async (data, thunkApi) => { try { const { authToken, monitor } = data; - const res = await axiosInstance.post( - `/monitors/delete/${monitor._id}`, - {}, - { - headers: { - Authorization: `Bearer ${authToken}`, - "Content-Type": "application/json", - }, - } - ); + const res = await axiosInstance.delete(`/monitors/${monitor._id}`, { + headers: { + Authorization: `Bearer ${authToken}`, + "Content-Type": "application/json", + }, + }); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/Server/routes/authRoute.js b/Server/routes/authRoute.js index 137434b7a..b01e90294 100644 --- a/Server/routes/authRoute.js +++ b/Server/routes/authRoute.js @@ -23,7 +23,7 @@ const { //Auth routes router.post("/register", upload.single("profileImage"), registerController); router.post("/login", loginController); -router.post( +router.put( "/user/:userId", upload.single("profileImage"), verifyJWT, diff --git a/Server/routes/monitorRoute.js b/Server/routes/monitorRoute.js index ae7a5852e..1f50c9e70 100644 --- a/Server/routes/monitorRoute.js +++ b/Server/routes/monitorRoute.js @@ -8,12 +8,12 @@ router.get("/:monitorId", monitorController.getMonitorById); router.get("/user/:userId", monitorController.getMonitorsByUserId); router.post("/", monitorController.createMonitor); -router.post( - "/delete/:monitorId", +router.delete( + "/:monitorId", verifyOwnership(Monitor, "monitorId"), monitorController.deleteMonitor ); -router.post( +router.put( "/edit/:monitorId", verifyOwnership(Monitor, "monitorId"), monitorController.editMonitor