1 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
3 import { VideoModel } from './video'
4 import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
5 import { VideoBlacklist } from '../../../shared/models/videos'
6 import { CONSTRAINTS_FIELDS } from '../../initializers'
9 tableName: 'videoBlacklist',
12 fields: [ 'videoId' ],
17 export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
20 @Is('VideoBlacklistReason', value => throwIfNotValid(value, isVideoBlacklistReasonValid, 'reason'))
21 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_BLACKLIST.REASON.max))
34 @ForeignKey(() => VideoModel)
38 @BelongsTo(() => VideoModel, {
46 static listForApi (start: number, count: number, sort: SortType) {
50 order: getSortOnModel(sort.sortModel, sort.sortValue),
59 return VideoBlacklistModel.findAndCountAll(query)
60 .then(({ rows, count }) => {
68 static loadByVideoId (id: number) {
75 return VideoBlacklistModel.findOne(query)
78 toFormattedJSON (): VideoBlacklist {
79 const video = this.Video
83 createdAt: this.createdAt,
84 updatedAt: this.updatedAt,
86 unfederated: this.unfederated,
92 description: video.description,
93 duration: video.duration,
96 dislikes: video.dislikes,