14 } from 'sequelize-typescript'
15 import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
16 import { VideoModel } from './video'
17 import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
18 import { Emailer } from '../../lib/emailer'
19 import { VideoBlacklist } from '../../../shared/models/videos'
20 import { CONSTRAINTS_FIELDS } from '../../initializers'
23 tableName: 'videoBlacklist',
26 fields: [ 'videoId' ],
31 export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
34 @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason'))
35 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
44 @ForeignKey(() => VideoModel)
48 @BelongsTo(() => VideoModel, {
57 static sendBlacklistEmailNotification (instance: VideoBlacklistModel) {
58 return Emailer.Instance.addVideoBlacklistReportJob(instance.videoId, instance.reason)
62 static sendUnblacklistEmailNotification (instance: VideoBlacklistModel) {
63 return Emailer.Instance.addVideoUnblacklistReportJob(instance.videoId)
66 static listForApi (start: number, count: number, sort: SortType) {
70 order: getSortOnModel(sort.sortModel, sort.sortValue),
79 return VideoBlacklistModel.findAndCountAll(query)
80 .then(({ rows, count }) => {
88 static loadByVideoId (id: number) {
95 return VideoBlacklistModel.findOne(query)
98 toFormattedJSON (): VideoBlacklist {
99 const video = this.Video
103 createdAt: this.createdAt,
104 updatedAt: this.updatedAt,
111 description: video.description,
112 duration: video.duration,
115 dislikes: video.dislikes,