]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Cleanup invalid rates/comments/shares
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index 7df0ed18df7e89b83aa464035730d2e878ff622b..fb52b35d932e86c0abb32277a72767f15a745d46 100644 (file)
@@ -1,4 +1,5 @@
 import * as Sequelize from 'sequelize'
+import { Op } from 'sequelize'
 import * as Bluebird from 'bluebird'
 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
@@ -200,4 +201,17 @@ export class VideoShareModel extends Model<VideoShareModel> {
 
     return VideoShareModel.findAndCountAll(query)
   }
+
+  static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) {
+    const query = {
+      where: {
+        updatedAt: {
+          [Op.lt]: beforeUpdatedAt
+        },
+        videoId
+      }
+    }
+
+    return VideoShareModel.destroy(query)
+  }
 }