From 4d7ddf7be1b5ebcbdd1be59bf3fc537bd1932eb0 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 20 Jun 2023 15:34:33 +0100 Subject: [PATCH] add notification rule --- CommonServer/Services/ProjectService.ts | 23 +++++++++++++++++++--- CommonServer/Services/TeamMemberService.ts | 9 +++++++++ CommonServer/Services/UserService.ts | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CommonServer/Services/ProjectService.ts b/CommonServer/Services/ProjectService.ts index 84b6336624..a385467f54 100755 --- a/CommonServer/Services/ProjectService.ts +++ b/CommonServer/Services/ProjectService.ts @@ -47,6 +47,8 @@ import MailService from './MailService'; import logger from '../Utils/Logger'; import Email from 'Common/Types/Email'; import EmailTemplateType from 'Common/Types/Email/EmailTemplateType'; +import UserService from './UserService'; +import UserNotificationRuleService from './UserNotificationRuleService'; export class Service extends DatabaseService { public constructor(postgresDatabase?: PostgresDatabase) { @@ -324,15 +326,15 @@ export class Service extends DatabaseService { }, }); } - + + createdItem = await this.addDefaultIncidentSeverity(createdItem); createdItem = await this.addDefaultProjectTeams(createdItem); createdItem = await this.addDefaultMonitorStatus(createdItem); createdItem = await this.addDefaultIncidentState(createdItem); createdItem = await this.addDefaultScheduledMaintenanceState( createdItem ); - createdItem = await this.addDefaultIncidentSeverity(createdItem); - + return createdItem; } @@ -604,6 +606,21 @@ export class Service extends DatabaseService { createdItem.createdByUserId! ); + const user: User | null = await UserService.findOneById({ + id: createdItem.createdByUserId!, + props: { + isRoot: true, + }, + select:{ + isEmailVerified: true, + email: true + } + }); + + if(user && user.isEmailVerified){ + await UserNotificationRuleService.addDefaultNotifictionRuleForUser(createdItem.id!, user.id!, user.email!); + } + return createdItem; } diff --git a/CommonServer/Services/TeamMemberService.ts b/CommonServer/Services/TeamMemberService.ts index 7450dcbf90..8a0436a37a 100644 --- a/CommonServer/Services/TeamMemberService.ts +++ b/CommonServer/Services/TeamMemberService.ts @@ -31,6 +31,7 @@ import logger from '../Utils/Logger'; import BadDataException from 'Common/Types/Exception/BadDataException'; import PositiveNumber from 'Common/Types/PositiveNumber'; import TeamMember from 'Model/Models/TeamMember'; +import UserNotificationRuleService from './UserNotificationRuleService'; export class TeamMemberService extends DatabaseService { public constructor(postgresDatabase?: PostgresDatabase) { @@ -153,6 +154,10 @@ export class TeamMemberService extends DatabaseService { }, select: { userId: true, + user: { + email: true, + isEmailVerified: true, + }, projectId: true, }, limit: LIMIT_MAX, @@ -165,6 +170,10 @@ export class TeamMemberService extends DatabaseService { for (const item of items) { await this.refreshTokens(item.userId!, item.projectId!); + + if(updateBy.data.hasAcceptedInvitation && item.user?.isEmailVerified) { + await UserNotificationRuleService.addDefaultNotifictionRuleForUser(item.projectId!, item.userId!, item.user?.email!); + } } return { updateBy, carryForward: onUpdate.carryForward }; diff --git a/CommonServer/Services/UserService.ts b/CommonServer/Services/UserService.ts index 5fa7a82476..2808717f8c 100755 --- a/CommonServer/Services/UserService.ts +++ b/CommonServer/Services/UserService.ts @@ -103,6 +103,7 @@ export class Service extends DatabaseService { await TeamMemberService.findBy({ query: { userId: user.id!, + hasAcceptedInvitation: true }, select: { projectId: true,