]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/author.ts
Async signature and various fixes
[github/Chocobozzz/PeerTube.git] / server / models / video / author.ts
index 4a115e328fe55836b39719d1eb90ccc08c102253..3222c483494f82774b82128a41b5dd578ddc64d9 100644 (file)
@@ -4,7 +4,6 @@ import { isUserUsernameValid } from '../../helpers'
 
 import { addMethodsToModel } from '../utils'
 import {
-  AuthorClass,
   AuthorInstance,
   AuthorAttributes,
 
@@ -74,30 +73,18 @@ function associate (models) {
   })
 }
 
-findOrCreateAuthor = function (
-  name: string,
-  podId: number,
-  userId: number,
-  transaction: Sequelize.Transaction,
-  callback: AuthorMethods.FindOrCreateAuthorCallback
-) {
+findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) {
   const author = {
     name,
     podId,
     userId
   }
 
-  const query: any = {
+  const query: Sequelize.FindOrInitializeOptions<AuthorAttributes> = {
     where: author,
-    defaults: author
+    defaults: author,
+    transaction
   }
 
-  if (transaction !== null) query.transaction = transaction
-
-  Author.findOrCreate(query).asCallback(function (err, result) {
-    if (err) return callback(err)
-
-    // [ instance, wasCreated ]
-    return callback(null, result[0])
-  })
+  return Author.findOrCreate(query).then(([ authorInstance ]) => authorInstance)
 }