13 } from 'sequelize-typescript'
14 import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
15 import { VideoModel } from './video'
16 import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel'
17 import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
18 import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
19 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
22 tableName: 'videoBlacklist',
25 fields: [ 'videoId' ],
30 export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
33 @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason'))
34 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
43 @Is('VideoBlacklistType', value => throwIfNotValid(value, isVideoBlacklistTypeValid, 'type'))
45 type: VideoBlacklistType
53 @ForeignKey(() => VideoModel)
57 @BelongsTo(() => VideoModel, {
65 static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) {
66 const query: IFindOptions<VideoBlacklistModel> = {
69 order: getSortOnModel(sort.sortModel, sort.sortValue),
76 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
85 query.where = { type }
88 return VideoBlacklistModel.findAndCountAll(query)
89 .then(({ rows, count }) => {
97 static loadByVideoId (id: number) {
104 return VideoBlacklistModel.findOne(query)
107 toFormattedJSON (): VideoBlacklist {
110 createdAt: this.createdAt,
111 updatedAt: this.updatedAt,
113 unfederated: this.unfederated,
116 video: this.Video.toFormattedJSON()