+import * as Bluebird from 'bluebird'
+import { Op } from 'sequelize'
import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
+import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models'
+import { ServerBlock } from '@shared/models'
import { AccountModel } from '../account/account'
-import { ServerModel } from './server'
-import { ServerBlock } from '../../../shared/models/blocklist'
import { getSort, searchAttribute } from '../utils'
-import * as Bluebird from 'bluebird'
-import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
-import { Op } from 'sequelize'
+import { ServerModel } from './server'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
return ServerBlocklistModel.findOne(query)
}
+ static listHostsBlockedBy (accountIds: number[]): Bluebird<string[]> {
+ const query = {
+ attributes: [ ],
+ where: {
+ accountId: {
+ [Op.in]: accountIds
+ }
+ },
+ include: [
+ {
+ attributes: [ 'host' ],
+ model: ServerModel.unscoped(),
+ required: true
+ }
+ ]
+ }
+
+ return ServerBlocklistModel.findAll(query)
+ .then(entries => entries.map(e => e.BlockedServer.host))
+ }
+
static listForApi (parameters: {
start: number
count: number
}
}
- console.log(search)
-
return ServerBlocklistModel
.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_SERVER ])
.findAndCountAll<MServerBlocklistAccountServer>(query)