2 Account rates per video.
4 import { values } from 'lodash'
5 import * as Sequelize from 'sequelize'
7 import { VIDEO_RATE_TYPES } from '../../initializers'
9 import { addMethodsToModel } from '../utils'
11 AccountVideoRateInstance,
12 AccountVideoRateAttributes,
14 AccountVideoRateMethods
15 } from './account-video-rate-interface'
17 let AccountVideoRate: Sequelize.Model<AccountVideoRateInstance, AccountVideoRateAttributes>
18 let load: AccountVideoRateMethods.Load
20 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
21 AccountVideoRate = sequelize.define<AccountVideoRateInstance, AccountVideoRateAttributes>('AccountVideoRate',
24 type: DataTypes.ENUM(values(VIDEO_RATE_TYPES)),
31 fields: [ 'videoId', 'accountId', 'type' ],
38 const classMethods = [
43 addMethodsToModel(AccountVideoRate, classMethods)
45 return AccountVideoRate
48 // ------------------------------ STATICS ------------------------------
50 function associate (models) {
51 AccountVideoRate.belongsTo(models.Video, {
59 AccountVideoRate.belongsTo(models.Account, {
68 load = function (accountId: number, videoId: number, transaction: Sequelize.Transaction) {
69 const options: Sequelize.FindOptions<AccountVideoRateAttributes> = {
75 if (transaction) options.transaction = transaction
77 return AccountVideoRate.findOne(options)