feat: Add optional notification email when invite is accepted (#3718)

* feat: Add optional notification email when invite is accepted

* Refactor to use beforeSend
This commit is contained in:
Tom Moor
2022-07-02 15:40:40 +03:00
committed by GitHub
parent ee22a127f6
commit 863f22750f
14 changed files with 169 additions and 66 deletions

View File

@@ -7,7 +7,6 @@ import {
Column,
IsIP,
IsEmail,
HasOne,
Default,
IsIn,
BeforeDestroy,
@@ -164,15 +163,14 @@ class User extends ParanoidModel {
}
// associations
@HasOne(() => User, "suspendedById")
@BelongsTo(() => User, "suspendedById")
suspendedBy: User | null;
@ForeignKey(() => User)
@Column(DataType.UUID)
suspendedById: string | null;
@HasOne(() => User, "invitedById")
@BelongsTo(() => User, "invitedById")
invitedBy: User | null;
@ForeignKey(() => User)
@@ -292,11 +290,12 @@ class User extends ParanoidModel {
};
updateSignedIn = (ip: string) => {
this.lastSignedInAt = new Date();
const now = new Date();
this.lastActiveAt = now;
this.lastActiveIp = ip;
this.lastSignedInAt = now;
this.lastSignedInIp = ip;
return this.save({
hooks: false,
});
return this.save({ hooks: false });
};
/**
@@ -521,6 +520,14 @@ class User extends ParanoidModel {
},
transaction: options.transaction,
}),
NotificationSetting.findOrCreate({
where: {
userId: model.id,
teamId: model.teamId,
event: "emails.invite_accepted",
},
transaction: options.transaction,
}),
]);
};