Skip to content

Commit

Permalink
Merge pull request #1311 from bluewave-labs/fix/be/delete-hardware-ch…
Browse files Browse the repository at this point in the history
…ecks

add deleteHardwareChecksByMonitorId
  • Loading branch information
ajhollid authored Dec 12, 2024
2 parents 903b98b + f42bddd commit 48d4625
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions Server/controllers/monitorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ const deleteMonitor = async (req, res, next) => {
await req.db.deleteChecks(monitor._id);
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
await req.db.deleteNotificationsByMonitorId(monitor._id);
await req.db.deleteHardwareChecksByMonitorId(monitor._id);
} catch (error) {
logger.error({
message: `Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`,
Expand Down
6 changes: 5 additions & 1 deletion Server/db/mongo/MongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ import {
//****************************************
// Hardware Checks
//****************************************
import { createHardwareCheck } from "./modules/hardwareCheckModule.js";
import {
createHardwareCheck,
deleteHardwareChecksByMonitorId,
} from "./modules/hardwareCheckModule.js";

//****************************************
// Checks
Expand Down Expand Up @@ -213,6 +216,7 @@ export default {
createPageSpeedCheck,
deletePageSpeedChecksByMonitorId,
createHardwareCheck,
deleteHardwareChecksByMonitorId,
createMaintenanceWindow,
getMaintenanceWindowsByTeamId,
getMaintenanceWindowById,
Expand Down
14 changes: 13 additions & 1 deletion Server/db/mongo/modules/hardwareCheckModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ const createHardwareCheck = async (hardwareCheckData) => {
}
};

export { createHardwareCheck };
const deleteHardwareChecksByMonitorId = async (monitorId) => {
try {
const result = await HardwareCheck.deleteMany({ monitorId });
console.log("deleted hardware checks", result);
return result.deletedCount;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "deleteHardwareChecksByMonitorId";
throw error;
}
};

export { createHardwareCheck, deleteHardwareChecksByMonitorId };

0 comments on commit 48d4625

Please sign in to comment.