]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/database-utils.ts
Add compatibility with other Linked Signature algorithms
[github/Chocobozzz/PeerTube.git] / server / helpers / database-utils.ts
index 9b861a88ccd3c417bf963ae659979ab57c28482b..1005d2cf19694f16e3f0cf1f000834a9c3a83972 100644 (file)
@@ -21,17 +21,21 @@ function retryTransactionWrapper <T, A> (
   arg1: A
 ): Promise<T>
 
+function retryTransactionWrapper <T> (
+  functionToRetry: () => Promise<T> | Bluebird<T>
+): Promise<T>
+
 function retryTransactionWrapper <T> (
   functionToRetry: (...args: any[]) => Promise<T> | Bluebird<T>,
   ...args: any[]
 ): Promise<T> {
   return transactionRetryer<T>(callback => {
-    functionToRetry.apply(this, args)
+    functionToRetry.apply(null, args)
         .then((result: T) => callback(null, result))
         .catch(err => callback(err))
   })
   .catch(err => {
-    logger.error('Cannot execute %s with many retries.', functionToRetry.toString(), { err })
+    logger.error(`Cannot execute ${functionToRetry.name} with many retries.`, { err })
     throw err
   })
 }
@@ -62,9 +66,17 @@ function updateInstanceWithAnother <T extends Model<T>> (instanceToUpdate: Model
   }
 }
 
+function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
+  Object.keys(savedFields).forEach(key => {
+    const value = savedFields[key]
+    instance.set(key, value)
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
+  resetSequelizeInstance,
   retryTransactionWrapper,
   transactionRetryer,
   updateInstanceWithAnother