fix: use correct callback for geo find queries

This commit is contained in:
biniam 2019-02-12 11:58:33 -05:00
parent c7d23d18d0
commit 5e0c73bec7
2 changed files with 60 additions and 55 deletions

View File

@ -1531,6 +1531,7 @@ DataAccessObject.find = function find(query, options, cb) {
const near = query && geo.nearFilter(query.where);
const supportsGeo = !!connector.buildNearFilter;
let geoQueryObject;
if (near) {
if (supportsGeo) {
@ -1558,8 +1559,10 @@ DataAccessObject.find = function find(query, options, cb) {
queryGeo(ctx.query);
});
}
function queryGeo(query) {
// already handled
return cb.promise;
}
}
function geoCallbackWithoutNotify(err, data) {
const memory = new Memory();
const modelName = self.modelName;
@ -1580,7 +1583,7 @@ DataAccessObject.find = function find(query, options, cb) {
});
// FIXME: apply "includes" and other transforms - see allCb below
memory.all(modelName, query, options, cb);
memory.all(modelName, geoQueryObject, options, allCb);
} else {
cb(null, []);
}
@ -1607,16 +1610,13 @@ DataAccessObject.find = function find(query, options, cb) {
geoCallbackWithoutNotify(null, results);
});
}
function queryGeo(query) {
geoQueryObject = query;
const geoCallback = options.notify === false ? geoCallbackWithoutNotify : geoCallbackWithNotify;
invokeConnectorMethod(connector, 'all', self, [{}], options, geoCallback);
}
// already handled
return cb.promise;
}
}
const allCb = function(err, data) {
function allCb(err, data) {
if (!err && Array.isArray(data)) {
async.map(data, function(item, next) {
const Model = self.lookupModel(item);
@ -1709,7 +1709,7 @@ DataAccessObject.find = function find(query, options, cb) {
} else {
cb(err, data || []);
}
};
}
if (options.notify === false) {
invokeConnectorMethod(connector, 'all', self, [query], options, allCb);

View File

@ -654,6 +654,7 @@ describe('basic-querying', function() {
if (err) done(err);
users.should.have.property('length', 3);
users[0].name.should.equal('John Lennon');
users[0].should.be.instanceOf(User);
users[0].addressLoc.should.not.be.null();
done();
});
@ -677,6 +678,7 @@ describe('basic-querying', function() {
if (err) done(err);
users.should.have.property('length', 2);
users[0].name.should.equal('John Lennon');
users[0].should.be.instanceOf(User);
users[0].addressLoc.should.not.be.null();
users[0].vip.should.be.true();
done();
@ -708,6 +710,7 @@ describe('basic-querying', function() {
if (err) done(err);
users.should.have.property('length', 1);
users[0].name.should.equal('John Lennon');
users[0].should.be.instanceOf(User);
users[0].addressLoc.should.not.be.null();
users[0].vip.should.be.true();
users[0].order.should.equal(2);
@ -738,6 +741,7 @@ describe('basic-querying', function() {
users.should.have.property('length', 2);
users[0].addressLoc.should.not.be.null();
users[0].name.should.equal('Paul McCartney');
users[0].should.be.instanceOf(User);
users[1].addressLoc.should.not.equal(null);
users[1].name.should.equal('John Lennon');
done();
@ -775,6 +779,7 @@ describe('basic-querying', function() {
users.should.have.property('length', 1);
users[0].addressLoc.should.not.be.null();
users[0].name.should.equal('John Lennon');
users[0].should.be.instanceOf(User);
users[0].vip.should.be.true();
done();
});