refactor: add Joi validation, rename to updateNotifications, add default case

This commit is contained in:
ashu130698 committed 2026-03-05 23:06:41 +05:30
1 parent 8eca81c8be
commit 9c17fbe79c
4 files changed
+27 -23

No files matched your search

@@ -41,7 +41,7 @@ export interface IMonitorsRepository {
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<MonitorsSummary>;
findGroupsByTeamId(teamId: string): Promise<string[]>;
removeNotificationFromMonitors(notificationId: string): Promise<void>;
bulkUpdateNotifications(monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set", teamId: string): Promise<number>;
updateNotifications(monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set", teamId: string): Promise<number>;
deleteByTeamIdsNotIn(teamIds: string[]): Promise<number>;
findAllMonitorIds(): Promise<string[]>;
}
@@ -298,7 +298,7 @@ class MongoMonitorsRepository implements IMonitorsRepository {
await MonitorModel.updateMany({ notifications: notificationId }, { $pull: { notifications: notificationId } });
};
bulkUpdateNotifications = async (
updateNotifications = async (
monitorIds: string[],
notificationIds: string[],
action: "add" | "remove" | "set",
@@ -323,6 +323,8 @@ class MongoMonitorsRepository implements IMonitorsRepository {
case "set":
update = { $set: { notifications: notificationIds } };
break;
default:
throw new AppError({ message: `Invalid action: ${action}`, status: 400 });
}
const result = await MonitorModel.updateMany(filter, update);