5 import { values } from 'lodash'
6 import * as Sequelize from 'sequelize'
8 import { VIDEO_RATE_TYPES } from '../initializers'
10 import { addMethodsToModel } from './utils'
13 UserVideoRateInstance,
14 UserVideoRateAttributes,
17 } from './user-video-rate-interface'
19 let UserVideoRate: Sequelize.Model<UserVideoRateInstance, UserVideoRateAttributes>
20 let load: UserVideoRateMethods.Load
22 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
23 UserVideoRate = sequelize.define<UserVideoRateInstance, UserVideoRateAttributes>('UserVideoRate',
26 type: DataTypes.ENUM(values(VIDEO_RATE_TYPES)),
33 fields: [ 'videoId', 'userId', 'type' ],
40 const classMethods = [
45 addMethodsToModel(UserVideoRate, classMethods)
50 // ------------------------------ STATICS ------------------------------
52 function associate (models) {
53 UserVideoRate.belongsTo(models.Video, {
61 UserVideoRate.belongsTo(models.User, {
70 load = function (userId: number, videoId: number, transaction: Sequelize.Transaction, callback: UserVideoRateMethods.LoadCallback) {
71 const options: Sequelize.FindOptions = {
77 if (transaction) options.transaction = transaction
79 return UserVideoRate.findOne(options).asCallback(callback)