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'
11 Account rates per video.
14 tableName: 'accountVideoRate',
17 fields: [ 'videoId', 'accountId' ],
22 export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
25 @Column(DataType.ENUM(values(VIDEO_RATE_TYPES)))
34 @ForeignKey(() => VideoModel)
38 @BelongsTo(() => VideoModel, {
46 @ForeignKey(() => AccountModel)
50 @BelongsTo(() => AccountModel, {
58 static load (accountId: number, videoId: number, transaction: Transaction) {
59 const options: IFindOptions<AccountVideoRateModel> = {
65 if (transaction) options.transaction = transaction
67 return AccountVideoRateModel.findOne(options)