]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/server/server-blocklist.ts
Lowercase video tags search
[github/Chocobozzz/PeerTube.git] / server / models / server / server-blocklist.ts
index 705ed2c6b9027704a498ac9f7d373136bc963f42..3e96871911f6215b9f613d776056811e58d45a9e 100644 (file)
@@ -3,17 +3,19 @@ import { AccountModel } from '../account/account'
 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
       }
     ]
@@ -21,12 +23,12 @@ enum ScopeNames {
   [ScopeNames.WITH_SERVER]: {
     include: [
       {
-        model: () => ServerModel,
+        model: ServerModel,
         required: true
       }
     ]
   }
-})
+}))
 
 @Table({
   tableName: 'serverBlocklist',
@@ -67,14 +69,13 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
 
   @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
@@ -105,16 +106,16 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
 
     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
     }
   }