Files
Checkmate/Server/controllers/notificationController.js
2025-02-16 19:32:52 -08:00

43 lines
1.3 KiB
JavaScript

class NotificationController {
constructor(notificationService) {
this.notificationService = notificationService;
this.triggerNotification = this.triggerNotification.bind(this);
}
async triggerNotification(req, res, next) {
try {
const { monitorId, type, platform, config } = req.body;
const networkResponse = {
monitor: { _id: monitorId, name: "Test Monitor", url: "http://www.google.com" },
status: false,
statusChanged: true,
prevStatus: true,
};
if (type === "webhook") {
const notification = {
type,
platform,
config
};
await this.notificationService.sendWebhookNotification(
networkResponse,
notification
);
}
return res.success({
msg: "Notification sent successfully"
});
} catch (error) {
error.service = "NotificationController";
error.method = "triggerNotification";
next(error);
}
}
}
export default NotificationController;