diff --git a/server/db/mongo/modules/maintenanceWindowModule.js b/server/db/mongo/modules/maintenanceWindowModule.js index 4f16fceb6..f7fea4636 100755 --- a/server/db/mongo/modules/maintenanceWindowModule.js +++ b/server/db/mongo/modules/maintenanceWindowModule.js @@ -34,10 +34,11 @@ const createMaintenanceWindow = async (maintenanceWindowData) => { } }; -const getMaintenanceWindowById = async (maintenanceWindowId) => { +const getMaintenanceWindowById = async ({ id, teamId }) => { try { - const maintenanceWindow = await MaintenanceWindow.findById({ - _id: maintenanceWindowId, + const maintenanceWindow = await MaintenanceWindow.findOne({ + _id: id, + teamId: teamId, }); return maintenanceWindow; } catch (error) { @@ -95,10 +96,11 @@ const getMaintenanceWindowsByTeamId = async (teamId, query) => { * @returns {Promise>} An array of MaintenanceWindow documents. * @throws {Error} If there is an error retrieving the documents. */ -const getMaintenanceWindowsByMonitorId = async (monitorId) => { +const getMaintenanceWindowsByMonitorId = async ({ monitorId, teamId }) => { try { const maintenanceWindows = await MaintenanceWindow.find({ monitorId: monitorId, + teamId: teamId, }); return maintenanceWindows; } catch (error) { @@ -116,9 +118,9 @@ const getMaintenanceWindowsByMonitorId = async (monitorId) => { * @returns {Promise} The deleted MaintenanceWindow document. * @throws {Error} If there is an error deleting the document. */ -const deleteMaintenanceWindowById = async (maintenanceWindowId) => { +const deleteMaintenanceWindowById = async ({ id, teamId }) => { try { - const maintenanceWindow = await MaintenanceWindow.findByIdAndDelete(maintenanceWindowId); + const maintenanceWindow = await MaintenanceWindow.findOneAndDelete({ _id: id, teamId }); return maintenanceWindow; } catch (error) { error.service = SERVICE_NAME; @@ -167,9 +169,9 @@ const deleteMaintenanceWindowByUserId = async (userId) => { } }; -const editMaintenanceWindowById = async (maintenanceWindowId, maintenanceWindowData) => { +const editMaintenanceWindowById = async ({ id, body, teamId }) => { try { - const editedMaintenanceWindow = await MaintenanceWindow.findByIdAndUpdate(maintenanceWindowId, maintenanceWindowData, { new: true }); + const editedMaintenanceWindow = await MaintenanceWindow.findByIdAndUpdate(id, body, { new: true }); return editedMaintenanceWindow; } catch (error) { error.service = SERVICE_NAME; diff --git a/server/routes/maintenanceWindowRoute.js b/server/routes/maintenanceWindowRoute.js index 7ba3ac855..774434ed6 100755 --- a/server/routes/maintenanceWindowRoute.js +++ b/server/routes/maintenanceWindowRoute.js @@ -1,7 +1,4 @@ import { Router } from "express"; -import { verifyOwnership } from "../middleware/verifyOwnership.js"; -import { verifyTeamAccess } from "../middleware/verifyTeamAccess.js"; -import Monitor from "../db/models/Monitor.js"; import MaintenanceWindow from "../db/models/MaintenanceWindow.js"; class MaintenanceWindowRoutes { constructor(maintenanceWindowController) { @@ -13,11 +10,11 @@ class MaintenanceWindowRoutes { this.router.post("/", this.mwController.createMaintenanceWindows); this.router.get("/team/", this.mwController.getMaintenanceWindowsByTeamId); - this.router.get("/monitor/:monitorId", verifyOwnership(Monitor, "monitorId"), this.mwController.getMaintenanceWindowsByMonitorId); + this.router.get("/monitor/:monitorId", this.mwController.getMaintenanceWindowsByMonitorId); this.router.get("/:id", this.mwController.getMaintenanceWindowById); - this.router.put("/:id", verifyTeamAccess(MaintenanceWindow, "id"), this.mwController.editMaintenanceWindow); - this.router.delete("/:id", verifyTeamAccess(MaintenanceWindow, "id"), this.mwController.deleteMaintenanceWindow); + this.router.put("/:id", this.mwController.editMaintenanceWindow); + this.router.delete("/:id", this.mwController.deleteMaintenanceWindow); } getRouter() {