refactor: server emit events (#11780)
This commit is contained in:
@@ -2,17 +2,12 @@ import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { isEqual } from 'lodash';
|
||||
import { DEFAULT_EXTERNAL_DOMAIN } from 'src/constants';
|
||||
import { SystemConfigCore } from 'src/cores/system-config.core';
|
||||
import { OnEmit } from 'src/decorators';
|
||||
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 {
|
||||
AlbumInviteEvent,
|
||||
AlbumUpdateEvent,
|
||||
OnEvents,
|
||||
SystemConfigUpdateEvent,
|
||||
UserSignupEvent,
|
||||
} from 'src/interfaces/event.interface';
|
||||
import { ArgOf } from 'src/interfaces/event.interface';
|
||||
import {
|
||||
IEmailJob,
|
||||
IJobRepository,
|
||||
@@ -30,7 +25,7 @@ import { getFilenameExtension } from 'src/utils/file';
|
||||
import { getPreferences } from 'src/utils/preferences';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationService implements OnEvents {
|
||||
export class NotificationService {
|
||||
private configCore: SystemConfigCore;
|
||||
|
||||
constructor(
|
||||
@@ -46,7 +41,8 @@ export class NotificationService implements OnEvents {
|
||||
this.configCore = SystemConfigCore.create(systemMetadataRepository, logger);
|
||||
}
|
||||
|
||||
async onConfigValidateEvent({ oldConfig, newConfig }: SystemConfigUpdateEvent) {
|
||||
@OnEmit({ event: 'onConfigValidate', priority: -100 })
|
||||
async onConfigValidate({ oldConfig, newConfig }: ArgOf<'onConfigValidate'>) {
|
||||
try {
|
||||
if (
|
||||
newConfig.notifications.smtp.enabled &&
|
||||
@@ -60,17 +56,20 @@ export class NotificationService implements OnEvents {
|
||||
}
|
||||
}
|
||||
|
||||
async onUserSignupEvent({ notify, id, tempPassword }: UserSignupEvent) {
|
||||
@OnEmit({ event: 'onUserSignup' })
|
||||
async onUserSignup({ notify, id, tempPassword }: ArgOf<'onUserSignup'>) {
|
||||
if (notify) {
|
||||
await this.jobRepository.queue({ name: JobName.NOTIFY_SIGNUP, data: { id, tempPassword } });
|
||||
}
|
||||
}
|
||||
|
||||
async onAlbumUpdateEvent({ id, updatedBy }: AlbumUpdateEvent) {
|
||||
@OnEmit({ event: 'onAlbumUpdate' })
|
||||
async onAlbumUpdate({ id, updatedBy }: ArgOf<'onAlbumUpdate'>) {
|
||||
await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_UPDATE, data: { id, senderId: updatedBy } });
|
||||
}
|
||||
|
||||
async onAlbumInviteEvent({ id, userId }: AlbumInviteEvent) {
|
||||
@OnEmit({ event: 'onAlbumInvite' })
|
||||
async onAlbumInvite({ id, userId }: ArgOf<'onAlbumInvite'>) {
|
||||
await this.jobRepository.queue({ name: JobName.NOTIFY_ALBUM_INVITE, data: { id, recipientId: userId } });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user