Skip to content

Commit a1ed406

Browse files
committed
Merge pull request #84 from kuzzleio/fix-rc-73-paginate-fetchAll
fixed #73
2 parents 114c603 + d2af824 commit a1ed406

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/kuzzleDataCollection.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,27 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
346346
* @returns {Object} this
347347
*/
348348
KuzzleDataCollection.prototype.fetchAllDocuments = function (options, cb) {
349+
var filters = {};
350+
349351
if (!cb && typeof options === 'function') {
350352
cb = options;
351353
options = null;
352354
}
353355

356+
// copying pagination options to the search filter
357+
if (options) {
358+
if (options.from) {
359+
filters.from = options.from;
360+
}
361+
362+
if (options.size) {
363+
filters.size = options.size;
364+
}
365+
}
366+
354367
this.kuzzle.callbackRequired('KuzzleDataCollection.fetchAll', cb);
355368

356-
this.advancedSearch({}, options, cb);
369+
this.advancedSearch(filters, options, cb);
357370

358371
return this;
359372
};

test/kuzzleDataCollection/methods.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var
22
should = require('should'),
33
rewire = require('rewire'),
4+
sinon = require('sinon'),
45
proxyquire = require('proxyquire'),
56
Kuzzle = rewire('../../src/kuzzle'),
67
KuzzleDataCollection = rewire('../../src/kuzzleDataCollection'),
@@ -539,6 +540,17 @@ describe('KuzzleDataCollection methods', function () {
539540
collection.fetchAllDocuments({}, function () {});
540541
should(emitted).be.true();
541542
});
543+
544+
it('should handle the from and size options', () => {
545+
var
546+
collection = kuzzle.dataCollectionFactory(expectedQuery.collection),
547+
stub = sinon.stub(collection, 'advancedSearch');
548+
549+
collection.fetchAllDocuments({from: 123, size: 456}, function () {});
550+
should(stub.calledOnce).be.true();
551+
should(stub.calledWithMatch({from: 123, size: 456})).be.true();
552+
stub.restore();
553+
});
542554
});
543555

544556
describe('#getMapping', function () {

0 commit comments

Comments
 (0)