14 } from 'sequelize-typescript'
15 import { throwIfNotValid } from '../utils'
16 import { UserModel } from './user'
17 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
18 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
19 import { clearCacheByUserId } from '../../lib/oauth-model'
22 tableName: 'userNotificationSetting',
30 export class UserNotificationSettingModel extends Model<UserNotificationSettingModel> {
35 'UserNotificationSettingNewVideoFromSubscription',
36 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newVideoFromSubscription')
39 newVideoFromSubscription: UserNotificationSettingValue
44 'UserNotificationSettingNewCommentOnMyVideo',
45 value => throwIfNotValid(value, isUserNotificationSettingValid, 'newCommentOnMyVideo')
48 newCommentOnMyVideo: UserNotificationSettingValue
53 'UserNotificationSettingVideoAbuseAsModerator',
54 value => throwIfNotValid(value, isUserNotificationSettingValid, 'videoAbuseAsModerator')
57 videoAbuseAsModerator: UserNotificationSettingValue
62 'UserNotificationSettingBlacklistOnMyVideo',
63 value => throwIfNotValid(value, isUserNotificationSettingValid, 'blacklistOnMyVideo')
66 blacklistOnMyVideo: UserNotificationSettingValue
68 @ForeignKey(() => UserModel)
72 @BelongsTo(() => UserModel, {
88 static removeTokenCache (instance: UserNotificationSettingModel) {
89 return clearCacheByUserId(instance.userId)
92 toFormattedJSON (): UserNotificationSetting {
94 newCommentOnMyVideo: this.newCommentOnMyVideo,
95 newVideoFromSubscription: this.newVideoFromSubscription,
96 videoAbuseAsModerator: this.videoAbuseAsModerator,
97 blacklistOnMyVideo: this.blacklistOnMyVideo