1 import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2 import { AccountModel } from './account'
3 import { getSort } from '../utils'
4 import { AccountBlock } from '../../../shared/models/blocklist'
7 WITH_ACCOUNTS = 'WITH_ACCOUNTS'
11 [ScopeNames.WITH_ACCOUNTS]: {
14 model: () => AccountModel,
19 model: () => AccountModel,
28 tableName: 'accountBlocklist',
31 fields: [ 'accountId', 'targetAccountId' ],
35 fields: [ 'targetAccountId' ]
39 export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
47 @ForeignKey(() => AccountModel)
51 @BelongsTo(() => AccountModel, {
59 ByAccount: AccountModel
61 @ForeignKey(() => AccountModel)
63 targetAccountId: number
65 @BelongsTo(() => AccountModel, {
67 name: 'targetAccountId',
73 BlockedAccount: AccountModel
75 static isAccountMutedBy (accountId: number, targetAccountId: number) {
85 return AccountBlocklistModel.unscoped()
90 static loadByAccountAndTarget (accountId: number, targetAccountId: number) {
98 return AccountBlocklistModel.findOne(query)
101 static listForApi (accountId: number, start: number, count: number, sort: string) {
105 order: getSort(sort),
111 return AccountBlocklistModel
112 .scope([ ScopeNames.WITH_ACCOUNTS ])
113 .findAndCountAll(query)
114 .then(({ rows, count }) => {
115 return { total: count, data: rows }
119 toFormattedJSON (): AccountBlock {
121 byAccount: this.ByAccount.toFormattedJSON(),
122 blockedAccount: this.BlockedAccount.toFormattedJSON(),
123 createdAt: this.createdAt