]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/account/user-video-history.ts
Refactor middleware helpers
[github/Chocobozzz/PeerTube.git] / server / models / account / user-video-history.ts
index 15cb399c952bc909305e331baf8cece53bccd45d..a862fc45fb859b0d842877c888b76233aec0962a 100644 (file)
@@ -67,7 +67,7 @@ export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> {
     })
   }
 
-  static removeHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) {
+  static removeUserHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) {
     const query: DestroyOptions = {
       where: {
         userId: user.id
@@ -76,11 +76,23 @@ export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> {
     }
 
     if (beforeDate) {
-      query.where.updatedAt = {
+      query.where['updatedAt'] = {
         [Op.lt]: beforeDate
       }
     }
 
     return UserVideoHistoryModel.destroy(query)
   }
+
+  static removeOldHistory (beforeDate: string) {
+    const query: DestroyOptions = {
+      where: {
+        updatedAt: {
+          [Op.lt]: beforeDate
+        }
+      }
+    }
+
+    return UserVideoHistoryModel.destroy(query)
+  }
 }