2016-08-16 15:31:45 -05:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const parallel = require('async/parallel')
|
|
|
|
|
|
|
|
const utils = {
|
2016-10-02 05:19:02 -05:00
|
|
|
listForApiWithCount
|
2016-08-16 15:31:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|