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' ]
25 fields: [ 'targetAccountId' ]
28 fields: [ 'accountId', 'targetAccountId' ],
35 const classMethods = [
37 loadByAccountAndTarget
39 addMethodsToModel(AccountFollow, classMethods)
44 // ------------------------------ STATICS ------------------------------
46 function associate (models) {
47 AccountFollow.belongsTo(models.Account, {
52 as: 'accountFollowers',
56 AccountFollow.belongsTo(models.Account, {
58 name: 'targetAccountId',
61 as: 'accountFollowing',
66 loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
74 return AccountFollow.findOne(query)