refactor(backend): move notifications update endpoint to monitors route and handle security feedback

This commit is contained in:
ashu130698 committed 2026-03-10 22:57:55 +05:30
1 parent 5578fdf17f
commit 0fc338db2f
9 files changed
+78 -42

No files matched your search

@@ -1,9 +1,8 @@
import { Request, Response, NextFunction } from "express";
import { Notification } from "@/types/index.js";
import { createNotificationBodyValidation, bulkEditNotificationBodyValidation } from "@/validation/notificationValidation.js";
import { createNotificationBodyValidation } from "@/validation/notificationValidation.js";
import { AppError } from "@/utils/AppError.js";
import { IMonitorsRepository } from "@/repositories/index.js";
import { INotificationsService } from "@/service/index.js";
import { requireTeamId } from "./controllerUtils.js";
@@ -12,10 +11,8 @@ const SERVICE_NAME = "NotificationController";
class NotificationController {
static SERVICE_NAME = SERVICE_NAME;
private notificationsService: INotificationsService;
private monitorsRepository: IMonitorsRepository;
constructor(notificationsService: INotificationsService, monitorsRepository: IMonitorsRepository) {
constructor(notificationsService: INotificationsService) {
this.notificationsService = notificationsService;
this.monitorsRepository = monitorsRepository;
}
get serviceName() {
@@ -150,25 +147,6 @@ class NotificationController {
}
};
// Handler for bulk editing monitor notification associations
bulkEditMonitorNotifications = async (req: Request, res: Response, next: NextFunction) => {
try {
bulkEditNotificationBodyValidation.parse(req.body);
const teamId = requireTeamId(req.user?.teamId);
const { monitorIds, notificationIds, action } = req.body;
const modifiedCount = await this.monitorsRepository.updateNotifications(monitorIds, notificationIds, action, teamId);
return res.status(200).json({
success: true,
msg: `Notifications updated successfully on ${modifiedCount} monitor(s)`,
data: { modifiedCount },
});
} catch (error) {
next(error);
}
};
testAllNotifications = async (req: Request, res: Response, next: NextFunction) => {
try {
@@ -178,9 +156,9 @@ class NotificationController {
throw new AppError({ message: "Team ID is required", status: 400 });
}
const monitor = await this.monitorsRepository.findById(monitorId, teamId);
// Removed logic since that function shouldn't be here, testing notifications is separate from this controller.
const notifications: string[] = []; // Fix TS definition error temporarily.
const notifications = monitor.notifications;
if (notifications.length === 0) {
throw new AppError({ message: "No notifications", status: 400 });
}