notificaitons provider

This commit is contained in:
Alex Holliday committed 2026-01-19 00:48:20 +00:00
1 parent c2487f0134
commit 7d6bc4b2dc
8 files changed
+134 -25

No files matched your search

@@ -1,4 +1,7 @@
import type { HardwareStatusPayload, Monitor, MonitorStatusResponse } from "@/types/index.js";
import type { HardwareStatusPayload, Monitor, MonitorStatusResponse, Notification } from "@/types/index.js";
import { NotificationModel } from "@/db/models/index.js";
import { buildHardwareAlerts, shouldSendHardwareAlert } from "@/service/infrastructure/notificationProviders/utils.js";
import { INotificationsRepository } from "@/repositories/index.js";
export interface INotificationsService {
handleNotifications: (
monitor: Monitor,
@@ -9,6 +12,24 @@ export interface INotificationsService {
}
export class NotificationsService implements INotificationsService {
private notificationsRepository: INotificationsRepository;
constructor(notificationsRepository: INotificationsRepository) {
this.notificationsRepository = notificationsRepository;
}
private send = (notification: Notification, monitor: Monitor, monitorStatusResponse: MonitorStatusResponse) => {
console.log(notification);
};
private sendNotifications = async (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse) => {
const notifications = await this.notificationsRepository.findByMonitorId(monitor.id);
console.log({ notifications });
const tasks = notifications.map((notification) => {
this.send(notification, monitor, monitorStatusResponse);
});
return true;
};
handleNotifications = async (
monitor: Monitor,
monitorStatusResponse: MonitorStatusResponse,
@@ -32,18 +53,18 @@ export class NotificationsService implements INotificationsService {
// We shoul dsend a notificaiton
const shouldSend = shouldSendHardwareAlert(monitor, monitorStatusResponse);
if (shouldSend === false) return false;
console.log(JSON.stringify(monitor, null, 2));
console.log(JSON.stringify(monitorStatusResponse, null, 2));
// const [alerts, discordContent] = await this.notificationUtils.buildHardwareAlerts(networkResponse);
// if (alerts.length === 0) return false;
// const { subject, html } = await this.notificationUtils.buildHardwareEmail(networkResponse, alerts);
// const content = await this.notificationUtils.buildHardwareNotificationMessage(alerts, monitor);
// const webhookBody = await this.notificationUtils.buildHardwareWebhookBody(alerts, monitor);
// const success = await this.notifyAll({ notificationIDs, subject, html, content, discordContent, webhookBody });
return true;
return await this.sendNotifications(monitor, monitorStatusResponse);
}
return false;
// We should send a notification for non-hardware monitor status change
return await this.sendNotifications(monitor, monitorStatusResponse);
};
}