+ static listHostsBlockedBy (accountIds: number[]): Promise<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 getBlockStatus (byAccountIds: number[], hosts: string[]): Promise<{ host: string, accountId: number }[]> {
+ const rawQuery = `SELECT "server"."host", "serverBlocklist"."accountId" ` +
+ `FROM "serverBlocklist" ` +
+ `INNER JOIN "server" ON "server"."id" = "serverBlocklist"."targetServerId" ` +
+ `WHERE "server"."host" IN (:hosts) ` +
+ `AND "serverBlocklist"."accountId" IN (${createSafeIn(ServerBlocklistModel.sequelize, byAccountIds)})`
+
+ return ServerBlocklistModel.sequelize.query(rawQuery, {
+ type: QueryTypes.SELECT as QueryTypes.SELECT,
+ replacements: { hosts }
+ })
+ }
+
+ static listForApi (parameters: {
+ start: number
+ count: number
+ sort: string
+ search?: string
+ accountId: number
+ }) {
+ const { start, count, sort, search, accountId } = parameters
+