import { ServerModel } from './server'
import { ServerBlock } from '../../../shared/models/blocklist'
import { getSort } from '../utils'
+import * as Bluebird from 'bluebird'
+import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
WITH_SERVER = 'WITH_SERVER'
}
-@Scopes({
+@Scopes(() => ({
[ScopeNames.WITH_ACCOUNT]: {
include: [
{
- model: () => AccountModel,
+ model: AccountModel,
required: true
}
]
[ScopeNames.WITH_SERVER]: {
include: [
{
- model: () => ServerModel,
+ model: ServerModel,
required: true
}
]
}
-})
+}))
@Table({
tableName: 'serverBlocklist',
@BelongsTo(() => ServerModel, {
foreignKey: {
- name: 'targetServerId',
allowNull: false
},
onDelete: 'CASCADE'
})
- ServerBlocked: ServerModel
+ BlockedServer: ServerModel
- static loadByAccountAndHost (accountId: number, host: string) {
+ static loadByAccountAndHost (accountId: number, host: string): Bluebird<MServerBlocklist> {
const query = {
where: {
accountId
return ServerBlocklistModel
.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_SERVER ])
- .findAndCountAll(query)
+ .findAndCountAll<MServerBlocklistAccountServer>(query)
.then(({ rows, count }) => {
return { total: count, data: rows }
})
}
- toFormattedJSON (): ServerBlock {
+ toFormattedJSON (this: MServerBlocklistFormattable): ServerBlock {
return {
byAccount: this.ByAccount.toFormattedJSON(),
- serverBlocked: this.ServerBlocked.toFormattedJSON(),
+ blockedServer: this.BlockedServer.toFormattedJSON(),
createdAt: this.createdAt
}
}