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