add controller method

This commit is contained in:
Alex Holliday
2025-06-16 12:16:52 +08:00
parent bc3801edc0
commit 3cdc21f1be
2 changed files with 16 additions and 3 deletions

View File

@@ -1,4 +1,3 @@
import Monitor from "../db/models/Monitor.js";
import {
getMonitorByIdParamValidation,
getMonitorByIdQueryValidation,
@@ -16,8 +15,6 @@ import {
getHardwareDetailsByIdQueryValidation,
} from "../validation/joi.js";
import sslChecker from "ssl-checker";
import jwt from "jsonwebtoken";
import { getTokenFromHeaders } from "../utils/utils.js";
import logger from "../utils/logger.js";
import { handleError, handleValidationError } from "./controllerUtils.js";
import axios from "axios";

View File

@@ -193,6 +193,22 @@ class NotificationController {
next(handleError(error, SERVICE_NAME, "editNotification"));
}
};
testAllNotifications = async (req, res, next) => {
try {
const { monitorId } = req.body;
const monitor = await this.db.getMonitorById(monitorId);
const notifications = monitor.notifications;
if (notifications.length === 0) throw new Error("No notifications");
const result = await this.notificationService.testAllNotifications(notifications);
if (!result) throw new Error("Failed to send all notifications");
return res.success({
msg: "All notifications sent successfully",
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "testAllNotifications"));
}
};
}
export default NotificationController;