import { Op, QueryTypes } from 'sequelize'
import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models'
-import { AttributesOnly } from '@shared/core-utils'
import { ServerBlock } from '@shared/models'
+import { AttributesOnly } from '@shared/typescript-utils'
import { AccountModel } from '../account/account'
-import { createSafeIn, getSort, searchAttribute } from '../utils'
+import { createSafeIn, getSort, searchAttribute } from '../shared'
import { ServerModel } from './server'
enum ScopeNames {
order: getSort(sort),
where: {
accountId,
+
...searchAttribute(search, '$BlockedServer.host$')
}
}
- return ServerBlocklistModel
- .scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_SERVER ])
- .findAndCountAll<MServerBlocklistAccountServer>(query)
- .then(({ rows, count }) => {
- return { total: count, data: rows }
- })
+ return Promise.all([
+ ServerBlocklistModel.scope(ScopeNames.WITH_SERVER).count(query),
+ ServerBlocklistModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_SERVER ]).findAll<MServerBlocklistAccountServer>(query)
+ ]).then(([ total, data ]) => ({ total, data }))
}
toFormattedJSON (this: MServerBlocklistFormattable): ServerBlock {