1 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
3 import { VideoModel } from './video'
4 import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
5 import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
6 import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos'
7 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
8 import { FindOptions } from 'sequelize'
11 tableName: 'videoBlacklist',
14 fields: [ 'videoId' ],
19 export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
22 @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason', true))
23 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
32 @Is('VideoBlacklistType', value => throwIfNotValid(value, isVideoBlacklistTypeValid, 'type'))
34 type: VideoBlacklistType
42 @ForeignKey(() => VideoModel)
46 @BelongsTo(() => VideoModel, {
54 static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) {
55 const query: FindOptions = {
58 order: getSortOnModel(sort.sortModel, sort.sortValue),
65 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }),
74 query.where = { type }
77 return VideoBlacklistModel.findAndCountAll(query)
78 .then(({ rows, count }) => {
86 static loadByVideoId (id: number) {
93 return VideoBlacklistModel.findOne(query)
96 toFormattedJSON (): VideoBlacklist {
99 createdAt: this.createdAt,
100 updatedAt: this.updatedAt,
102 unfederated: this.unfederated,
105 video: this.Video.toFormattedJSON()