1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Server: add user list sort/pagination

This commit is contained in:
Chocobozzz 2016-08-16 22:31:45 +02:00
parent 089ff2f204
commit 5c39adb731
11 changed files with 200 additions and 17 deletions

30
server/models/utils.js Normal file
View file

@ -0,0 +1,30 @@
'use strict'
const parallel = require('async/parallel')
const utils = {
listForApiWithCount: listForApiWithCount
}
function listForApiWithCount (query, start, count, sort, callback) {
const self = this
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)
const data = results[0]
const total = results[1]
return callback(null, data, total)
})
}
// ---------------------------------------------------------------------------
module.exports = utils