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' ],
25 fields: [ 'accountId' ]
28 fields: [ 'videoId', 'type' ]
32 export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
35 @Column(DataType.ENUM(values(VIDEO_RATE_TYPES)))
44 @ForeignKey(() => VideoModel)
48 @BelongsTo(() => VideoModel, {
56 @ForeignKey(() => AccountModel)
60 @BelongsTo(() => AccountModel, {
68 static load (accountId: number, videoId: number, transaction: Transaction) {
69 const options: IFindOptions<AccountVideoRateModel> = {
75 if (transaction) options.transaction = transaction
77 return AccountVideoRateModel.findOne(options)
80 static listAndCountAccountUrlsByVideoId (rateType: VideoRateType, videoId: number, start: number, count: number, t?: Transaction) {
91 attributes: [ 'actorId' ],
92 model: AccountModel.unscoped(),
96 attributes: [ 'url' ],
97 model: ActorModel.unscoped(),
105 return AccountVideoRateModel.findAndCountAll(query)