]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/schedule-video-update.ts
Add ability to schedule video publication
[github/Chocobozzz/PeerTube.git] / server / models / video / schedule-video-update.ts
index d4e37beb5ce245eaccb95e7a3923baa9257b8a6f..3cf5f6c99b06591fe81260f6479553d348d0eedc 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,10 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
     return ScheduleVideoUpdateModel.findAll(query)
   }
 
+  toFormattedJSON () {
+    return {
+      updateAt: this.updateAt,
+      privacy: this.privacy || undefined
+    }
+  }
 }