From 7a7724e66e4533523083e7336cd0d0c747c4a33b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 13 Nov 2017 17:39:41 +0100 Subject: Handle follow/accept --- server/models/account/account-follow.ts | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'server/models/account/account-follow.ts') 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 @@ +import { values } from 'lodash' import * as Sequelize from 'sequelize' import { addMethodsToModel } from '../utils' -import { - AccountFollowInstance, - AccountFollowAttributes, - - AccountFollowMethods -} from './account-follow-interface' +import { AccountFollowAttributes, AccountFollowInstance, AccountFollowMethods } from './account-follow-interface' +import { FOLLOW_STATES } from '../../initializers/constants' let AccountFollow: Sequelize.Model +let loadByAccountAndTarget: AccountFollowMethods.LoadByAccountAndTarget export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { AccountFollow = sequelize.define('AccountFollow', - { }, + { + state: { + type: DataTypes.ENUM(values(FOLLOW_STATES)), + allowNull: false + } + }, { indexes: [ { @@ -43,6 +46,7 @@ function associate (models) { name: 'accountId', allowNull: false }, + as: 'followers', onDelete: 'CASCADE' }) @@ -51,6 +55,18 @@ function associate (models) { name: 'targetAccountId', allowNull: false }, + as: 'following', onDelete: 'CASCADE' }) } + +loadByAccountAndTarget = function (accountId: number, targetAccountId: number) { + const query = { + where: { + accountId, + targetAccountId + } + } + + return AccountFollow.findOne(query) +} -- cgit v1.2.3