Client: add views information and sort
[oweals/peertube.git] / server / models / author.js
index 7d15fb6ecd92ba4baa28a8c6f9efacd5e5f521d2..34b0130971e12db40f7cd4043f2985734d3ba6f5 100644 (file)
@@ -25,7 +25,12 @@ module.exports = function (sequelize, DataTypes) {
           fields: [ 'podId' ]
         },
         {
-          fields: [ 'userId' ]
+          fields: [ 'userId' ],
+          unique: true
+        },
+        {
+          fields: [ 'name', 'podId' ],
+          unique: true
         }
       ],
       classMethods: {
@@ -79,7 +84,9 @@ function findOrCreateAuthor (name, podId, userId, transaction, callback) {
   if (transaction) query.transaction = transaction
 
   this.findOrCreate(query).asCallback(function (err, result) {
+    if (err) return callback(err)
+
     // [ instance, wasCreated ]
-    return callback(err, result[0])
+    return callback(null, result[0])
   })
 }