refactor(server): notification events (#10754)

This commit is contained in:
Jason Rasmussen
2024-07-03 22:06:20 -04:00
committed by GitHub
parent 0b88bef157
commit 81d12c0586
10 changed files with 92 additions and 69 deletions
+22 -2
View File
@@ -5,7 +5,13 @@ import { SystemConfigSmtpDto } from 'src/dtos/system-config.dto';
import { AlbumEntity } from 'src/entities/album.entity';
import { IAlbumRepository } from 'src/interfaces/album.interface';
import { IAssetRepository } from 'src/interfaces/asset.interface';
import { OnEvents, SystemConfigUpdate } from 'src/interfaces/event.interface';
import {
AlbumInviteEvent,
AlbumUpdateEvent,
OnEvents,
SystemConfigUpdateEvent,
UserSignupEvent,
} from 'src/interfaces/event.interface';
import {
IEmailJob,
IJobRepository,
@@ -38,7 +44,7 @@ export class NotificationService implements OnEvents {
this.configCore = SystemConfigCore.create(systemMetadataRepository, logger);
}
async onConfigValidateEvent({ newConfig }: SystemConfigUpdate) {
async onConfigValidateEvent({ newConfig }: SystemConfigUpdateEvent) {
try {
if (newConfig.notifications.smtp.enabled) {
await this.notificationRepository.verifySmtp(newConfig.notifications.smtp.transport);
@@ -49,6 +55,20 @@ export class NotificationService implements OnEvents {
}
}
async onUserSignupEvent({ notify, id, tempPassword }: UserSignupEvent) {
if (notify) {
await this.jobRepository.queue({ name: JobName.NOTIFY_SIGNUP, data: { id, tempPassword } });
}
}
async onAlbumUpdateEvent({ id, updatedBy }: AlbumUpdateEvent) {
await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_UPDATE, data: { id, senderId: updatedBy } });
}
async onAlbumInviteEvent({ id, userId }: AlbumInviteEvent) {
await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_INVITE, data: { id, recipientId: userId } });
}
async sendTestEmail(id: string, dto: SystemConfigSmtpDto) {
const user = await this.userRepository.get(id, { withDeleted: false });
if (!user) {