diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-13 17:39:41 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 7a7724e66e4533523083e7336cd0d0c747c4a33b (patch) | |
tree | 805299eb9c6829158cd17e5a823a84a3a54d8209 /server/models/account/account-follow.ts | |
parent | 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff) | |
download | PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip |
Handle follow/accept
Diffstat (limited to 'server/models/account/account-follow.ts')
-rw-r--r-- | server/models/account/account-follow.ts | 30 |
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 @@ | |||
1 | import { values } from 'lodash' | ||
1 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
2 | 3 | ||
3 | import { addMethodsToModel } from '../utils' | 4 | import { addMethodsToModel } from '../utils' |
4 | import { | 5 | import { AccountFollowAttributes, AccountFollowInstance, AccountFollowMethods } from './account-follow-interface' |
5 | AccountFollowInstance, | 6 | import { FOLLOW_STATES } from '../../initializers/constants' |
6 | AccountFollowAttributes, | ||
7 | |||
8 | AccountFollowMethods | ||
9 | } from './account-follow-interface' | ||
10 | 7 | ||
11 | let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> | 8 | let AccountFollow: Sequelize.Model<AccountFollowInstance, AccountFollowAttributes> |
9 | let loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget | ||
12 | 10 | ||
13 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 11 | export 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 | |||
63 | loadByAccountAndTarget = function (accountId: number, targetAccountId: number) { | ||
64 | const query = { | ||
65 | where: { | ||
66 | accountId, | ||
67 | targetAccountId | ||
68 | } | ||
69 | } | ||
70 | |||
71 | return AccountFollow.findOne(query) | ||
72 | } | ||