]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video.js
Server: transaction serializable for videos
[github/Chocobozzz/PeerTube.git] / server / models / video.js
index f51d08f06f4a4e430c9cbb811d881af6c80e4e78..b3060705d9cd981dfd6c4ecd4bf74caa77b6516a 100644 (file)
@@ -20,7 +20,6 @@ const customVideosValidators = require('../helpers/custom-validators').videos
 // ---------------------------------------------------------------------------
 
 module.exports = function (sequelize, DataTypes) {
-  // TODO: add indexes on searchable columns
   const Video = sequelize.define('Video',
     {
       id: {
@@ -219,7 +218,6 @@ function afterDestroy (video, options, next) {
 
       function (callback) {
         const params = {
-          name: video.name,
           remoteId: video.id
         }
 
@@ -249,6 +247,14 @@ function associate (models) {
     through: models.VideoTag,
     onDelete: 'cascade'
   })
+
+  this.hasMany(models.VideoAbuse, {
+    foreignKey: {
+      name: 'videoId',
+      allowNull: false
+    },
+    onDelete: 'cascade'
+  })
 }
 
 function generateMagnetUri () {
@@ -329,7 +335,8 @@ function toFormatedJSON () {
     duration: this.duration,
     tags: map(this.Tags, 'name'),
     thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(),
-    createdAt: this.createdAt
+    createdAt: this.createdAt,
+    updatedAt: this.updatedAt
   }
 
   return json
@@ -356,6 +363,7 @@ function toAddRemoteJSON (callback) {
       thumbnailData: thumbnailData.toString('binary'),
       tags: map(self.Tags, 'name'),
       createdAt: self.createdAt,
+      updatedAt: self.updatedAt,
       extname: self.extname
     }
 
@@ -373,6 +381,7 @@ function toUpdateRemoteJSON (callback) {
     duration: this.duration,
     tags: map(this.Tags, 'name'),
     createdAt: this.createdAt,
+    updatedAt: this.updatedAt,
     extname: this.extname
   }