add notification rule

This commit is contained in:
Simon Larsen 2023-06-20 15:34:33 +01:00
parent 9dfdd0841f
commit 4d7ddf7be1
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
3 changed files with 30 additions and 3 deletions

View File

@ -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<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
@ -324,15 +326,15 @@ export class Service extends DatabaseService<Model> {
},
});
}
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<Model> {
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;
}

View File

@ -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<TeamMember> {
public constructor(postgresDatabase?: PostgresDatabase) {
@ -153,6 +154,10 @@ export class TeamMemberService extends DatabaseService<TeamMember> {
},
select: {
userId: true,
user: {
email: true,
isEmailVerified: true,
},
projectId: true,
},
limit: LIMIT_MAX,
@ -165,6 +170,10 @@ export class TeamMemberService extends DatabaseService<TeamMember> {
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 };

View File

@ -103,6 +103,7 @@ export class Service extends DatabaseService<Model> {
await TeamMemberService.findBy({
query: {
userId: user.id!,
hasAcceptedInvitation: true
},
select: {
projectId: true,