mongoose-paginate-v2
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -0,0 +0,0 @@ --- |
@@ -0,0 +0,0 @@ --- |
@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct |
67
index.js
@@ -1,3 +0,1 @@ | ||
var Promise = require('bluebird'); | ||
/** | ||
@@ -20,2 +18,3 @@ * @param {Object} [query={}] | ||
*/ | ||
function paginate(query, options, callback) { | ||
@@ -28,3 +27,3 @@ query = query || {}; | ||
var sort = options.sort; | ||
var collation = options.collation; | ||
var collation = options.collation || {}; | ||
var populate = options.populate; | ||
@@ -50,3 +49,3 @@ var lean = options.lean || false; | ||
} else if (options.hasOwnProperty('page')) { | ||
page = options.page; | ||
page = parseInt(options.page); | ||
skip = (page - 1) * limit; | ||
@@ -59,40 +58,37 @@ } else { | ||
var promises = { | ||
docs: Promise.resolve([]), | ||
count: this.countDocuments(query).exec() | ||
}; | ||
const count = this.countDocuments(query).exec() | ||
const model = this.find(query) | ||
model.select(select) | ||
model.sort(sort) | ||
model.collation(collation) | ||
model.lean(lean); | ||
if (limit) { | ||
var query = this.find(query) | ||
.select(select) | ||
.sort(sort) | ||
.collation(collation) | ||
.skip(skip) | ||
.limit(limit) | ||
.lean(lean); | ||
model.skip(skip); | ||
model.limit(limit); | ||
} | ||
if (populate) { | ||
[].concat(populate).forEach(function(item) { | ||
query.populate(item); | ||
}); | ||
} | ||
if (populate) { | ||
model.populate(populate) | ||
} | ||
promises.docs = query.exec(); | ||
let docs = model.exec(); | ||
if (lean && leanWithId) { | ||
promises.docs = promises.docs.then(function(docs) { | ||
docs.forEach(function(doc) { | ||
doc.id = String(doc._id); | ||
}); | ||
return docs; | ||
if (lean && leanWithId) { | ||
docs = docs.then(function(docs) { | ||
docs.forEach(function(doc) { | ||
doc.id = String(doc._id); | ||
}); | ||
} | ||
return docs; | ||
}); | ||
} | ||
return Promise.props(promises) | ||
.then(function(data) { | ||
return Promise.all([count, docs]) | ||
.then(function(values) { | ||
var result = { | ||
[labelDocs]: data.docs, | ||
[labelTotal]: data.count, | ||
[labelDocs]: values[1], | ||
[labelTotal]: values[0], | ||
[labelLimit]: limit | ||
@@ -107,3 +103,3 @@ }; | ||
const pages = Math.ceil(data.count / limit) || 1; | ||
const pages = Math.ceil(values[0] / limit) || 1; | ||
@@ -133,5 +129,4 @@ result.hasPrevPage = false; | ||
return result; | ||
return Promise.resolve(result); | ||
}) | ||
.asCallback(callback); | ||
} | ||
@@ -138,0 +133,0 @@ |
{ | ||
"name": "mongoose-paginate-v2", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "A cursor based custom pagination library for Mongoose with customizable labels.", | ||
@@ -34,5 +34,3 @@ "main": "index.js", | ||
"homepage": "https://github.com/aravindnc/mongoose-paginate-v2#readme", | ||
"dependencies": { | ||
"bluebird": "3.5.1" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -39,0 +37,0 @@ "babel-cli": "^6.26.0", |
@@ -0,0 +0,0 @@ # mongoose-paginate-v2 |
@@ -0,0 +0,0 @@ // @author edwardhotchkiss |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23792
0
262
- Removedbluebird@3.5.1
- Removedbluebird@3.5.1(transitive)