Files
Checkmate/Server/controllers/notificationController.js
T

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2025-02-08 17:07:14 -08:00
class NotificationController {
constructor(notificationService) {
this.notificationService = notificationService;
2025-02-12 21:22:44 -08:00
this.triggerNotification = this.triggerNotification.bind(this);
2025-02-08 17:07:14 -08:00
}
2025-02-12 21:17:31 -08:00
async triggerNotification(req, res, next) {
2025-02-08 17:07:14 -08:00
try {
2025-02-12 18:54:34 -08:00
const { monitorId, type, config } = req.body;
2025-02-08 17:07:14 -08:00
const networkResponse = {
monitor: { _id: monitorId, name: "Test Monitor", url: "http://www.google.com" },
status: false,
statusChanged: true,
prevStatus: true,
};
if (type === "webhook") {
await this.notificationService.sendWebhookNotification(
networkResponse,
config
);
2025-02-08 17:07:14 -08:00
}
return res.success({
msg: "Notification sent successfully"
});
2025-02-08 17:07:14 -08:00
} catch (error) {
2025-02-12 21:17:31 -08:00
error.service = "NotificationController";
error.method = "triggerNotification";
next(error);
2025-02-08 17:07:14 -08:00
}
}
}
export default NotificationController;