fix: address PR review feedback and add Zod validation constraints
This commit is contained in:
1 parent
1706012e54
commit
1e6cf858c4
5 files changed
+11
-5
No files matched your search
@@ -41,7 +41,7 @@ export interface IMonitorsRepository {
|
|||||||
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<MonitorsSummary>;
|
findMonitorsSummaryByTeamId(teamId: string, config?: SummaryConfig): Promise<MonitorsSummary>;
|
||||||
findGroupsByTeamId(teamId: string): Promise<string[]>;
|
findGroupsByTeamId(teamId: string): Promise<string[]>;
|
||||||
removeNotificationFromMonitors(notificationId: string): Promise<void>;
|
removeNotificationFromMonitors(notificationId: string): Promise<void>;
|
||||||
updateNotifications(monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set", teamId: string): Promise<number>;
|
updateNotifications(teamId: string, monitorIds: string[], notificationIds: string[], action: "add" | "remove" | "set"): Promise<number>;
|
||||||
deleteByTeamIdsNotIn(teamIds: string[]): Promise<number>;
|
deleteByTeamIdsNotIn(teamIds: string[]): Promise<number>;
|
||||||
findAllMonitorIds(): Promise<string[]>;
|
findAllMonitorIds(): Promise<string[]>;
|
||||||
}
|
}
|
||||||
@@ -299,10 +299,10 @@ class MongoMonitorsRepository implements IMonitorsRepository {
|
|||||||
};
|
};
|
||||||
|
|
||||||
updateNotifications = async (
|
updateNotifications = async (
|
||||||
|
teamId: string,
|
||||||
monitorIds: string[],
|
monitorIds: string[],
|
||||||
notificationIds: string[],
|
notificationIds: string[],
|
||||||
action: "add" | "remove" | "set",
|
action: "add" | "remove" | "set"
|
||||||
teamId: string
|
|
||||||
): Promise<number> => {
|
): Promise<number> => {
|
||||||
let objectIds;
|
let objectIds;
|
||||||
let notificationObjectIds;
|
let notificationObjectIds;
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ export class MonitorService implements IMonitorService {
|
|||||||
notificationIds: string[];
|
notificationIds: string[];
|
||||||
action: "add" | "remove" | "set";
|
action: "add" | "remove" | "set";
|
||||||
}): Promise<number> => {
|
}): Promise<number> => {
|
||||||
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 notifications were updated, we should update the jobs in the queue
|
||||||
if (modifiedCount > 0) {
|
if (modifiedCount > 0) {
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ export class UserService implements IUserService {
|
|||||||
if (!html) {
|
if (!html) {
|
||||||
throw new Error("Failed to build welcome email 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({
|
this.logger.warn({
|
||||||
message: error instanceof Error ? error.message : "Unknown error",
|
message: error instanceof Error ? error.message : "Unknown error",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
|||||||
@@ -103,4 +103,10 @@ export const updateNotificationsValidation = z.object({
|
|||||||
monitorIds: z.array(z.string()).min(1, "At least one monitor ID is required"),
|
monitorIds: z.array(z.string()).min(1, "At least one monitor ID is required"),
|
||||||
notificationIds: z.array(z.string()),
|
notificationIds: z.array(z.string()),
|
||||||
action: z.enum(["add", "remove", "set"] as const),
|
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"],
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user