Merge pull request #3411 from bluewave-labs/fix/notification-controller-validation

fix: implement NotificationController missing validation
This commit is contained in:
Alexander Holliday authored and GitHub committed 2026-03-11 13:46:51 -07:00
commit e4a228e61e
11 files changed
+60 -68

No files matched your search

@@ -3,5 +3,5 @@ import type { NotificationMessage } from "@/types/notificationMessage.js";
export interface INotificationProvider {
sendMessage: (notification: Notification, message: NotificationMessage) => Promise<boolean>;
sendTestAlert(notification: Notification): Promise<boolean>;
sendTestAlert(notification: Partial<Notification>): Promise<boolean>;
}
@@ -13,7 +13,7 @@ export class DiscordProvider implements INotificationProvider {
this.logger = logger;
}
sendTestAlert = async (notification: Notification) => {
sendTestAlert = async (notification: Partial<Notification>) => {
if (!notification.address) {
return false;
}
@@ -14,7 +14,7 @@ export class EmailProvider implements INotificationProvider {
this.logger = logger;
}
async sendTestAlert(notification: Notification): Promise<boolean> {
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
const subject = "Test notification";
const html = await buildTestEmail(this.emailService);
@@ -13,7 +13,7 @@ export class MatrixProvider implements INotificationProvider {
this.logger = logger;
}
sendTestAlert = async (notification: Notification) => {
sendTestAlert = async (notification: Partial<Notification>) => {
const { homeserverUrl, accessToken, roomId } = notification;
if (!homeserverUrl || !accessToken || !roomId) {
return false;
@@ -14,7 +14,7 @@ export class PagerDutyProvider implements INotificationProvider {
this.logger = logger;
}
async sendTestAlert(notification: Notification): Promise<boolean> {
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
try {
await got.post("https://events.pagerduty.com/v2/enqueue", {
json: {
@@ -13,7 +13,7 @@ export class SlackProvider implements INotificationProvider {
this.logger = logger;
}
async sendTestAlert(notification: Notification): Promise<boolean> {
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
if (!notification.address) {
return false;
}
@@ -65,7 +65,7 @@ export class TeamsProvider implements INotificationProvider {
this.logger = logger;
}
async sendTestAlert(notification: Notification): Promise<boolean> {
async sendTestAlert(notification: Partial<Notification>): Promise<boolean> {
if (!notification.address) {
return false;
}
@@ -98,7 +98,7 @@ export class WebhookProvider implements INotificationProvider {
};
}
sendTestAlert = async (notification: Notification) => {
sendTestAlert = async (notification: Partial<Notification>) => {
if (!notification.address) {
return false;
}
@@ -8,14 +8,14 @@ import { ILogger } from "@/utils/logger.js";
import type { INotificationMessageBuilder } from "@/service/infrastructure/notificationMessageBuilder.js";
export interface INotificationsService {
createNotification: (notificationData: Partial<Notification>) => Promise<Notification>;
createNotification: (notificationData: Partial<Notification>, userId: string, teamId: string) => Promise<Notification>;
findById: (id: string, teamId: string) => Promise<Notification>;
findNotificationsByTeamId: (teamId: string) => Promise<Notification[]>;
updateById(id: string, teamId: string, updateData: Partial<Notification>): Promise<Notification>;
deleteById: (id: string, teamId: string) => Promise<Notification>;
handleNotifications: (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse, decision: MonitorActionDecision) => Promise<boolean>;
sendTestNotification: (notification: Notification) => Promise<boolean>;
sendTestNotification: (notification: Partial<Notification>) => Promise<boolean>;
testAllNotifications: (notificationIds: string[]) => Promise<boolean>;
}
@@ -141,7 +141,7 @@ export class NotificationsService implements INotificationsService {
return await this.sendNotifications(monitor, monitorStatusResponse, decision);
};
sendTestNotification = async (notification: Notification) => {
sendTestNotification = async (notification: Partial<Notification>) => {
switch (notification.type) {
case "email":
return await this.emailProvider.sendTestAlert(notification);
@@ -174,7 +174,9 @@ export class NotificationsService implements INotificationsService {
return true;
};
createNotification = async (notificationData: Partial<Notification>): Promise<Notification> => {
createNotification = async (notificationData: Partial<Notification>, userId: string, teamId: string): Promise<Notification> => {
notificationData.userId = userId;
notificationData.teamId = teamId;
return await this.notificationsRepository.create(notificationData);
};