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

@@ -72,6 +72,9 @@ export interface IMonitorService {
deleteMonitor(args: { teamId: string; monitorId: string }): Promise<Monitor>;
deleteAllMonitors(args: { teamId: string }): Promise<number>;
// notifications
updateNotifications(args: { teamId: string; monitorIds: string[]; notificationIds: string[]; action: "add" | "remove" | "set" }): Promise<number>;
// other
sendTestEmail(args: { to: string }): Promise<string>;
exportMonitorsToJSON(args: { teamId: string }): Promise<Monitor[]>;
@@ -442,6 +445,18 @@ export class MonitorService implements IMonitorService {
return editedMonitor;
};
updateNotifications = async ({ teamId, monitorIds, notificationIds, action }: { teamId: string; monitorIds: string[]; notificationIds: string[]; action: "add" | "remove" | "set" }): Promise<number> => {
const modifiedCount = await this.monitorsRepository.updateNotifications(monitorIds, notificationIds, action, teamId);
// If notifications were updated, we should update the jobs in the queue
if (modifiedCount > 0) {
const monitors = await this.monitorsRepository.findByIds(monitorIds);
await Promise.all(monitors.map(monitor => this.jobQueue.updateJob(monitor)));
}
return modifiedCount;
};
pauseMonitor = async ({ teamId, monitorId }: { teamId: string; monitorId: string }): Promise<Monitor> => {
const monitor = await this.monitorsRepository.togglePauseById(monitorId, teamId);
monitor.isActive === true ? await this.jobQueue.resumeJob(monitor) : await this.jobQueue.pauseJob(monitor);
+8 -5
View File
@@ -135,13 +135,13 @@ export class UserService implements IUserService {
user.password = this.hashPassword(user.password);
}
const newUser = await this.usersRepository.create(user, file);
const newUser = await this.usersRepository.create(user as User, file);
this.logger.debug({
message: "New user created",
service: SERVICE_NAME,
method: "registerUser",
details: newUser.id,
details: { id: newUser.id },
});
delete newUser.profileImage;
@@ -158,7 +158,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).catch((error: unknown) => {
this.emailService.sendEmail(newUser.email, "Welcome to Uptime Monitor", html as string).catch((error: unknown) => {
this.logger.warn({
message: error instanceof Error ? error.message : "Unknown error",
service: SERVICE_NAME,
@@ -199,13 +199,13 @@ export class UserService implements IUserService {
userData.password = this.hashPassword(userData.password);
}
const newUser = await this.usersRepository.create(userData, file);
const newUser = await this.usersRepository.create(userData as User, file);
this.logger.debug({
message: "New user created by superadmin",
service: SERVICE_NAME,
method: "createUser",
details: newUser.id,
details: { id: newUser.id },
});
newUser.profileImage = undefined;
@@ -280,6 +280,9 @@ export class UserService implements IUserService {
email,
url,
});
if (!html) {
throw new AppError({ message: "Failed to generate password reset email", status: 500 });
}
const msgId = await this.emailService.sendEmail(email, "Checkmate Password Reset", html);
return msgId;
};