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 AccountBlocked: AccountModel
75 static loadByAccountAndTarget (accountId: number, targetAccountId: number) {
83 return AccountBlocklistModel.findOne(query)
86 static listForApi (accountId: number, start: number, count: number, sort: string) {
96 return AccountBlocklistModel
97 .scope([ ScopeNames.WITH_ACCOUNTS ])
98 .findAndCountAll(query)
99 .then(({ rows, count }) => {
100 return { total: count, data: rows }
104 toFormattedJSON (): AccountBlock {
106 byAccount: this.ByAccount.toFormattedJSON(),
107 accountBlocked: this.AccountBlocked.toFormattedJSON(),
108 createdAt: this.createdAt