aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/account/account-follow.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/account/account-follow.ts')
-rw-r--r--server/models/account/account-follow.ts30
1 files changed, 23 insertions, 7 deletions
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index 9bf03b253..e6abc893a 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -1,18 +1,21 @@
1import { values } from 'lodash'
1import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
2 3
3import { addMethodsToModel } from '../utils' 4import { addMethodsToModel } from '../utils'
4import { 5import { AccountFollowAttributes, AccountFollowInstance, AccountFollowMethods } from './account-follow-interface'
5 AccountFollowInstance, 6import { FOLLOW_STATES } from '../../initializers/constants'
6 AccountFollowAttributes,
7
8 AccountFollowMethods
9} from './account-follow-interface'
10 7
11let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> 8let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes>
9let loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget
12 10
13export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 11export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
14 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow', 12 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
15 { }, 13 {
14 state: {
15 type: DataTypes.ENUM(values(FOLLOW_STATES)),
16 allowNull: false
17 }
18 },
16 { 19 {
17 indexes: [ 20 indexes: [
18 { 21 {
@@ -43,6 +46,7 @@ function associate (models) {
43 name: 'accountId', 46 name: 'accountId',
44 allowNull: false 47 allowNull: false
45 }, 48 },
49 as: 'followers',
46 onDelete: 'CASCADE' 50 onDelete: 'CASCADE'
47 }) 51 })
48 52
@@ -51,6 +55,18 @@ function associate (models) {
51 name: 'targetAccountId', 55 name: 'targetAccountId',
52 allowNull: false 56 allowNull: false
53 }, 57 },
58 as: 'following',
54 onDelete: 'CASCADE' 59 onDelete: 'CASCADE'
55 }) 60 })
56} 61}
62
63loadByAccountAndTarget = function (accountId: number, targetAccountId: number) {
64 const query = {
65 where: {
66 accountId,
67 targetAccountId
68 }
69 }
70
71 return AccountFollow.findOne(query)
72}