X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Faccount-blocklist.ts;h=e2f66d733c514e444baa071b71e50e8da24a6664;hb=a3b7421abb4192e215aa280418b62e96958c5e42;hp=efd6ed59e5a3c1a0b33b713fd51bf44818bd0fab;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index efd6ed59e..e2f66d733 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts @@ -3,27 +3,29 @@ import { AccountModel } from './account' import { getSort } from '../utils' import { AccountBlock } from '../../../shared/models/blocklist' import { Op } from 'sequelize' +import * as Bluebird from 'bluebird' +import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' enum ScopeNames { WITH_ACCOUNTS = 'WITH_ACCOUNTS' } -@Scopes({ +@Scopes(() => ({ [ScopeNames.WITH_ACCOUNTS]: { include: [ { - model: () => AccountModel, + model: AccountModel, required: true, as: 'ByAccount' }, { - model: () => AccountModel, + model: AccountModel, required: true, as: 'BlockedAccount' } ] } -}) +})) @Table({ tableName: 'accountBlocklist', @@ -73,17 +75,12 @@ export class AccountBlocklistModel extends Model { }) BlockedAccount: AccountModel - static isAccountMutedBy (accountId: number, targetAccountId: number) { - return AccountBlocklistModel.isAccountMutedByMulti([ accountId ], targetAccountId) - .then(result => result[accountId]) - } - static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) { const query = { attributes: [ 'accountId', 'id' ], where: { accountId: { - [Op.any]: accountIds + [Op.in]: accountIds }, targetAccountId }, @@ -103,7 +100,7 @@ export class AccountBlocklistModel extends Model { }) } - static loadByAccountAndTarget (accountId: number, targetAccountId: number) { + static loadByAccountAndTarget (accountId: number, targetAccountId: number): Bluebird { const query = { where: { accountId, @@ -126,13 +123,13 @@ export class AccountBlocklistModel extends Model { return AccountBlocklistModel .scope([ ScopeNames.WITH_ACCOUNTS ]) - .findAndCountAll(query) + .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } }) } - toFormattedJSON (): AccountBlock { + toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { return { byAccount: this.ByAccount.toFormattedJSON(), blockedAccount: this.BlockedAccount.toFormattedJSON(),