diff --git a/server/src/repositories/monitors/IMonitorsRepository.ts b/server/src/repositories/monitors/IMonitorsRepository.ts index 88c039881..8c5f63e7d 100644 --- a/server/src/repositories/monitors/IMonitorsRepository.ts +++ b/server/src/repositories/monitors/IMonitorsRepository.ts @@ -41,7 +41,7 @@ export interface IMonitorsRepository { findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise; findGroupsByTeamId(teamId: string): Promise; removeNotificationFromMonitors(notificationId: string): Promise; - updateNotifications(monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set", teamId: string): Promise; + updateNotifications(teamId: string, monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set"): Promise; deleteByTeamIdsNotIn(teamIds: string[]): Promise; findAllMonitorIds(): Promise; } diff --git a/server/src/repositories/monitors/MongoMonitorsRepository.ts b/server/src/repositories/monitors/MongoMonitorsRepository.ts index 07f9ee7bb..93056c747 100644 --- a/server/src/repositories/monitors/MongoMonitorsRepository.ts +++ b/server/src/repositories/monitors/MongoMonitorsRepository.ts @@ -299,10 +299,10 @@ class MongoMonitorsRepository implements IMonitorsRepository { }; updateNotifications = async ( + teamId: string, monitorIds: string[], notificationIds: string[], - action: "add" | "remove" | "set", - teamId: string + action: "add" | "remove" | "set" ): Promise => { let objectIds; let notificationObjectIds; diff --git a/server/src/service/business/monitorService.ts b/server/src/service/business/monitorService.ts index 6e0446645..ff7b87fe8 100644 --- a/server/src/service/business/monitorService.ts +++ b/server/src/service/business/monitorService.ts @@ -449,7 +449,7 @@ export class MonitorService implements IMonitorService { notificationIds: string[]; action: "add" | "remove" | "set"; }): Promise => { - const modifiedCount = await this.monitorsRepository.updateNotifications(monitorIds, notificationIds, action, teamId); + const modifiedCount = await this.monitorsRepository.updateNotifications(teamId, monitorIds, notificationIds, action); // If notifications were updated, we should update the jobs in the queue if (modifiedCount > 0) { diff --git a/server/src/service/business/userService.ts b/server/src/service/business/userService.ts index a4ef15cee..48ee5cfbf 100644 --- a/server/src/service/business/userService.ts +++ b/server/src/service/business/userService.ts @@ -166,7 +166,7 @@ export class UserService implements IUserService { if (!html) { throw new Error("Failed to build welcome email HTML"); } - this.emailService.sendEmail(newUser.email, "Welcome to Uptime Monitor", html as string).catch((error: unknown) => { + this.emailService.sendEmail(newUser.email, "Welcome to Uptime Monitor", html).catch((error: unknown) => { this.logger.warn({ message: error instanceof Error ? error.message : "Unknown error", service: SERVICE_NAME, diff --git a/server/src/validation/notificationValidation.ts b/server/src/validation/notificationValidation.ts index cf187f7b4..cc375ed2f 100644 --- a/server/src/validation/notificationValidation.ts +++ b/server/src/validation/notificationValidation.ts @@ -103,4 +103,10 @@ export const updateNotificationsValidation = z.object({ monitorIds: z.array(z.string()).min(1, "At least one monitor ID is required"), notificationIds: z.array(z.string()), action: z.enum(["add", "remove", "set"] as const), +}).refine((data) => { + if (data.action !== "set" && data.notificationIds.length === 0) return false; + return true; +}, { + message: "Notification IDs cannot be empty unless action is 'set'", + path: ["notificationIds"], });