]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/schedule-video-update.ts
Add reason when banning a user
[github/Chocobozzz/PeerTube.git] / server / models / video / schedule-video-update.ts
index d4e37beb5ce245eaccb95e7a3923baa9257b8a6f..1e56562e1974dae3f4f198036b6719a692796ea8 100644 (file)
@@ -25,7 +25,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
   @AllowNull(true)
   @Default(null)
   @Column
-  privacy: VideoPrivacy
+  privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED
 
   @CreatedAt
   createdAt: Date
@@ -45,6 +45,21 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
   })
   Video: VideoModel
 
+  static areVideosToUpdate () {
+    const query = {
+      logging: false,
+      attributes: [ 'id' ],
+      where: {
+        updateAt: {
+          [Sequelize.Op.lte]: new Date()
+        }
+      }
+    }
+
+    return ScheduleVideoUpdateModel.findOne(query)
+      .then(res => !!res)
+  }
+
   static listVideosToUpdate (t: Transaction) {
     const query = {
       where: {
@@ -68,4 +83,21 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
     return ScheduleVideoUpdateModel.findAll(query)
   }
 
+  static deleteByVideoId (videoId: number, t: Transaction) {
+    const query = {
+      where: {
+        videoId
+      },
+      transaction: t
+    }
+
+    return ScheduleVideoUpdateModel.destroy(query)
+  }
+
+  toFormattedJSON () {
+    return {
+      updateAt: this.updateAt,
+      privacy: this.privacy || undefined
+    }
+  }
 }