]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-channel.ts
Refactor options in models
[github/Chocobozzz/PeerTube.git] / server / models / video / video-channel.ts
index e4b12c517ccc71eeb61f0c70402a625cdcee87c9..9f04a57c64025f11baa6e9d02fee6f4ef1208141 100644 (file)
@@ -438,30 +438,6 @@ ON              "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
     }
   }
 
-  static listForApi (parameters: {
-    actorId: number
-    start: number
-    count: number
-    sort: string
-  }) {
-    const { actorId } = parameters
-
-    const query = {
-      offset: parameters.start,
-      limit: parameters.count,
-      order: getSort(parameters.sort)
-    }
-
-    return VideoChannelModel
-      .scope({
-        method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
-      })
-      .findAndCountAll(query)
-      .then(({ rows, count }) => {
-        return { total: count, data: rows }
-      })
-  }
-
   static listLocalsForSitemap (sort: string): Promise<MChannelActor[]> {
     const query = {
       attributes: [ ],
@@ -483,15 +459,33 @@ ON              "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
       .findAll(query)
   }
 
-  static searchForApi (options: {
-    actorId: number
-    search?: string
+  static listForApi (parameters: Pick<AvailableForListOptions, 'actorId'> & {
     start: number
     count: number
     sort: string
+  }) {
+    const { actorId } = parameters
+
+    const query = {
+      offset: parameters.start,
+      limit: parameters.count,
+      order: getSort(parameters.sort)
+    }
+
+    return VideoChannelModel
+      .scope({
+        method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ]
+      })
+      .findAndCountAll(query)
+      .then(({ rows, count }) => {
+        return { total: count, data: rows }
+      })
+  }
 
-    host?: string
-    handles?: string[]
+  static searchForApi (options: Pick<AvailableForListOptions, 'actorId' | 'search' | 'host' | 'handles'> & {
+    start: number
+    count: number
+    sort: string
   }) {
     let attributesInclude: any[] = [ literal('0 as similarity') ]
     let where: WhereOptions