1 import { logger } from '@server/helpers/logger'
2 import { UserModel } from '@server/models/user/user'
3 import { UserNotificationModel } from '@server/models/user/user-notification'
4 import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
5 import { UserNotificationType, UserRight } from '@shared/models'
6 import { AbstractNotification } from '../common/abstract-notification'
8 export class RegistrationRequestForModerators extends AbstractNotification <MRegistration> {
9 private moderators: MUserDefault[]
12 this.moderators = await UserModel.listWithRight(UserRight.MANAGE_REGISTRATIONS)
16 logger.info('Notifying %s moderators of new user registration request of %s.', this.moderators.length, this.payload.username)
19 getSetting (user: MUserWithNotificationSetting) {
20 return user.NotificationSetting.newUserRegistration
24 return this.moderators
27 createNotification (user: MUserWithNotificationSetting) {
28 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
29 type: UserNotificationType.NEW_USER_REGISTRATION_REQUEST,
31 userRegistrationId: this.payload.id
33 notification.UserRegistration = this.payload
38 createEmail (to: string) {
40 template: 'user-registration-request',
42 subject: `A new user wants to register: ${this.payload.username}`,
44 registration: this.payload