]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/account-video-rate.ts
Refractor and optimize AP collections
[github/Chocobozzz/PeerTube.git] / server / models / account / account-video-rate.ts
index e969e4a436b78c9c519baec342c1f0a9165bfb9e..508ab814f93fe34f94031f477dafcef90a0fa32d 100644 (file)
@@ -6,6 +6,7 @@ import { VideoRateType } from '../../../shared/models/videos'
 import { VIDEO_RATE_TYPES } from '../../initializers'
 import { VideoModel } from '../video/video'
 import { AccountModel } from './account'
+import { ActorModel } from '../activitypub/actor'
 
 /*
   Account rates per video.
@@ -66,4 +67,32 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
 
     return AccountVideoRateModel.findOne(options)
   }
+
+  static listAndCountAccountUrlsByVideoId (rateType: VideoRateType, videoId: number, start: number, count: number, t?: Transaction) {
+    const query = {
+      start,
+      count,
+      where: {
+        videoId,
+        type: rateType
+      },
+      transaction: t,
+      include: [
+        {
+          attributes: [ 'actorId' ],
+          model: AccountModel.unscoped(),
+          required: true,
+          include: [
+            {
+              attributes: [ 'url' ],
+              model: ActorModel.unscoped(),
+              required: true
+            }
+          ]
+        }
+      ]
+    }
+
+    return AccountVideoRateModel.findAndCountAll(query)
+  }
 }