From 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Dec 2017 17:53:50 +0100 Subject: Move models to typescript-sequelize --- server/lib/activitypub/process/process-follow.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'server/lib/activitypub/process/process-follow.ts') diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 320dc1138..ccaee43a6 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -1,10 +1,10 @@ -import { ActivityFollow } from '../../../../shared/models/activitypub/activity' -import { retryTransactionWrapper } from '../../../helpers' -import { database as db } from '../../../initializers' -import { AccountInstance } from '../../../models/account/account-interface' -import { logger } from '../../../helpers/logger' -import { sendAccept } from '../send/send-accept' +import { ActivityFollow } from '../../../../shared/models/activitypub' +import { logger, retryTransactionWrapper } from '../../../helpers' +import { sequelizeTypescript } from '../../../initializers' +import { AccountModel } from '../../../models/account/account' +import { AccountFollowModel } from '../../../models/account/account-follow' import { getOrCreateAccountAndServer } from '../account' +import { sendAccept } from '../send' async function processFollowActivity (activity: ActivityFollow) { const activityObject = activity.object @@ -21,7 +21,7 @@ export { // --------------------------------------------------------------------------- -function processFollow (account: AccountInstance, targetAccountURL: string) { +function processFollow (account: AccountModel, targetAccountURL: string) { const options = { arguments: [ account, targetAccountURL ], errorMessage: 'Cannot follow with many retries.' @@ -30,14 +30,14 @@ function processFollow (account: AccountInstance, targetAccountURL: string) { return retryTransactionWrapper(follow, options) } -async function follow (account: AccountInstance, targetAccountURL: string) { - await db.sequelize.transaction(async t => { - const targetAccount = await db.Account.loadByUrl(targetAccountURL, t) +async function follow (account: AccountModel, targetAccountURL: string) { + await sequelizeTypescript.transaction(async t => { + const targetAccount = await AccountModel.loadByUrl(targetAccountURL, t) if (!targetAccount) throw new Error('Unknown account') if (targetAccount.isOwned() === false) throw new Error('This is not a local account.') - const [ accountFollow ] = await db.AccountFollow.findOrCreate({ + const [ accountFollow ] = await AccountFollowModel.findOrCreate({ where: { accountId: account.id, targetAccountId: targetAccount.id -- cgit v1.2.3