]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/utils.js
Server: propagate video update to other pods
[github/Chocobozzz/PeerTube.git] / server / models / utils.js
index e798aabe67a0f67a2648f450f6c0f26879bc1191..49636b3d85e62cc6dcaf2aa90532d44dd06868b1 100644 (file)
@@ -1,28 +1,23 @@
 'use strict'
 
-const parallel = require('async/parallel')
-
 const utils = {
-  listForApiWithCount
+  getSort
 }
 
-function listForApiWithCount (query, start, count, sort, callback) {
-  const self = this
+// Translate for example "-name" to [ 'name', 'DESC' ]
+function getSort (value) {
+  let field
+  let direction
 
-  parallel([
-    function (asyncCallback) {
-      self.find(query).skip(start).limit(count).sort(sort).exec(asyncCallback)
-    },
-    function (asyncCallback) {
-      self.count(query, asyncCallback)
-    }
-  ], function (err, results) {
-    if (err) return callback(err)
+  if (value.substring(0, 1) === '-') {
+    direction = 'DESC'
+    field = value.substring(1)
+  } else {
+    direction = 'ASC'
+    field = value
+  }
 
-    const data = results[0]
-    const total = results[1]
-    return callback(null, data, total)
-  })
+  return [ field, direction ]
 }
 
 // ---------------------------------------------------------------------------