]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account.ts
Move typescript utils in its own directory
[github/Chocobozzz/PeerTube.git] / server / models / account / account.ts
index 665ecd595cf604a2b8c13e1b036028a4110f5fd2..619a598ddf15013d2d1eb34796c2280dedbb36d5 100644 (file)
@@ -17,7 +17,7 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import { ModelCache } from '@server/models/model-cache'
-import { AttributesOnly } from '@shared/core-utils'
+import { AttributesOnly } from '@shared/typescript-utils'
 import { Account, AccountSummary } from '../../../shared/models/actors'
 import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts'
 import { CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants'
@@ -52,6 +52,7 @@ export enum ScopeNames {
 export type SummaryOptions = {
   actorRequired?: boolean // Default: true
   whereActor?: WhereOptions
+  whereServer?: WhereOptions
   withAccountBlockerIds?: number[]
 }
 
@@ -65,12 +66,11 @@ export type SummaryOptions = {
 }))
 @Scopes(() => ({
   [ScopeNames.SUMMARY]: (options: SummaryOptions = {}) => {
-    const whereActor = options.whereActor || undefined
-
     const serverInclude: IncludeOptions = {
       attributes: [ 'host' ],
       model: ServerModel.unscoped(),
-      required: false
+      required: !!options.whereServer,
+      where: options.whereServer
     }
 
     const queryInclude: Includeable[] = [
@@ -78,7 +78,7 @@ export type SummaryOptions = {
         attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ],
         model: ActorModel.unscoped(),
         required: options.actorRequired ?? true,
-        where: whereActor,
+        where: options.whereActor,
         include: [
           serverInclude,
 
@@ -99,7 +99,7 @@ export type SummaryOptions = {
       queryInclude.push({
         attributes: [ 'id' ],
         model: AccountBlocklistModel.unscoped(),
-        as: 'BlockedAccounts',
+        as: 'BlockedBy',
         required: false,
         where: {
           accountId: {
@@ -228,10 +228,10 @@ export class AccountModel extends Model<Partial<AttributesOnly<AccountModel>>> {
       name: 'targetAccountId',
       allowNull: false
     },
-    as: 'BlockedAccounts',
+    as: 'BlockedBy',
     onDelete: 'CASCADE'
   })
-  BlockedAccounts: AccountBlocklistModel[]
+  BlockedBy: AccountBlocklistModel[]
 
   @BeforeDestroy
   static async sendDeleteIfOwned (instance: AccountModel, options) {
@@ -457,6 +457,6 @@ export class AccountModel extends Model<Partial<AttributesOnly<AccountModel>>> {
   }
 
   isBlocked () {
-    return this.BlockedAccounts && this.BlockedAccounts.length !== 0
+    return this.BlockedBy && this.BlockedBy.length !== 0
   }
 }