1 import { values } from 'lodash'
2 import * as Sequelize from 'sequelize'
4 import { addMethodsToModel } from '../utils'
5 import { AccountFollowAttributes, AccountFollowInstance, AccountFollowMethods } from './account-follow-interface'
6 import { FOLLOW_STATES } from '../../initializers/constants'
8 let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes>
9 let loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget
11 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
12 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
15 type: DataTypes.ENUM(values(FOLLOW_STATES)),
22 fields: [ 'accountId' ],
26 fields: [ 'targetAccountId' ],
33 const classMethods = [
36 addMethodsToModel(AccountFollow, classMethods)
41 // ------------------------------ STATICS ------------------------------
43 function associate (models) {
44 AccountFollow.belongsTo(models.Account, {
53 AccountFollow.belongsTo(models.Account, {
55 name: 'targetAccountId',
63 loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
71 return AccountFollow.findOne(query)