1 import { values } from 'lodash'
2 import { Transaction } from 'sequelize'
3 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
4 import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions'
5 import { VideoRateType } from '../../../shared/models/videos'
6 import { VIDEO_RATE_TYPES } from '../../initializers'
7 import { VideoModel } from '../video/video'
8 import { AccountModel } from './account'
9 import { ActorModel } from '../activitypub/actor'
12 Account rates per video.
15 tableName: 'accountVideoRate',
18 fields: [ 'videoId', 'accountId' ],
23 export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
26 @Column(DataType.ENUM(values(VIDEO_RATE_TYPES)))
35 @ForeignKey(() => VideoModel)
39 @BelongsTo(() => VideoModel, {
47 @ForeignKey(() => AccountModel)
51 @BelongsTo(() => AccountModel, {
59 static load (accountId: number, videoId: number, transaction: Transaction) {
60 const options: IFindOptions<AccountVideoRateModel> = {
66 if (transaction) options.transaction = transaction
68 return AccountVideoRateModel.findOne(options)
71 static listAndCountAccountUrlsByVideoId (rateType: VideoRateType, videoId: number, start: number, count: number, t?: Transaction) {
82 attributes: [ 'actorId' ],
83 model: AccountModel.unscoped(),
87 attributes: [ 'url' ],
88 model: ActorModel.unscoped(),
96 return AccountVideoRateModel.findAndCountAll(query)