]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Federate video update
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index 358491fd2d1bb9a8eeb5bc661196be6f73bcd7e9..22ac31a4a04a917bccaa55c685bb9474c499dbac 100644 (file)
@@ -1,9 +1,10 @@
 import * as Sequelize from 'sequelize'
 
 import { addMethodsToModel } from '../utils'
-import { VideoShareAttributes, VideoShareInstance } from './video-share-interface'
+import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface'
 
 let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes>
+let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
 
 export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
   VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare',
@@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
   )
 
   const classMethods = [
-    associate
+    associate,
+    loadAccountsByShare
   ]
   addMethodsToModel(VideoShare, classMethods)
 
@@ -47,3 +49,20 @@ function associate (models) {
     onDelete: 'cascade'
   })
 }
+
+loadAccountsByShare = function (videoId: number) {
+  const query = {
+    where: {
+      videoId
+    },
+    include: [
+      {
+        model: VideoShare['sequelize'].models.Account,
+        required: true
+      }
+    ]
+  }
+
+  return VideoShare.findAll(query)
+    .then(res => res.map(r => r.Account))
+}