]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Destroy user token when changing its role
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index c252fd64696bcc2714b29470a8dcbf46ba571ec3..56576f98c8efa3dafcf9c1889335e9f3c31343e2 100644 (file)
@@ -1,7 +1,9 @@
 import * as Sequelize from 'sequelize'
 import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
+import { AccountModel } from '../account/account'
 import { ActorModel } from '../activitypub/actor'
 import { VideoModel } from './video'
+import { VideoChannelModel } from './video-channel'
 
 enum ScopeNames {
   FULL = 'FULL',
@@ -99,4 +101,42 @@ export class VideoShareModel extends Model<VideoShareModel> {
     return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
       .then(res => res.map(r => r.Actor))
   }
+
+  static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) {
+    const query = {
+      attributes: [],
+      include: [
+        {
+          model: ActorModel,
+          required: true
+        },
+        {
+          attributes: [],
+          model: VideoModel,
+          required: true,
+          include: [
+            {
+              attributes: [],
+              model: VideoChannelModel.unscoped(),
+              required: true,
+              include: [
+                {
+                  attributes: [],
+                  model: AccountModel.unscoped(),
+                  required: true,
+                  where: {
+                    actorId: actorOwnerId
+                  }
+                }
+              ]
+            }
+          ]
+        }
+      ],
+      transaction: t
+    }
+
+    return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
+      .then(res => res.map(r => r.Actor))
+  }
 }