Skip to content

Commit

Permalink
- mongodb in memory for integration tests
Browse files Browse the repository at this point in the history
- bug and test fixes
  • Loading branch information
Lazaro Fernandes Lima Suleiman committed Feb 16, 2018
1 parent d06a7d4 commit c97317a
Show file tree
Hide file tree
Showing 4 changed files with 1,425 additions and 22 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function paginate(query, options, callback) {
let populate = options.populate;
let lean = options.lean || false;
let leanWithId = options.leanWithId ? options.leanWithId : true;
let limit = options.limit ? options.limit : 10;
let limit = options.limit || Number.MAX_SAFE_INTEGER;
let page, offset, skip, promises;
if (options.offset) {
offset = options.offset;
Expand Down Expand Up @@ -65,23 +65,23 @@ function paginate(query, options, callback) {
promises = Object.keys(promises).map((x) => promises[x]);
return Promise.all(promises).then((data) => {
let result = {
docs: data.docs,
total: data.count,
docs: data[0],
total: data[1],
limit: limit
};
if (offset !== undefined) {
result.offset = offset;
}
if (page !== undefined) {
result.page = page;
result.pages = Math.ceil(data.count / limit) || 1;
result.pages = Math.ceil(result.total / limit) || 1;
}
if (typeof callback === 'function') {
return callback(null, result);
}
let promise = new Promise();
promise.resolve(result);
return promise;
return new Promise((resolve, reject) => {
resolve(result);
});
});
}

Expand Down
Loading

0 comments on commit c97317a

Please sign in to comment.