fix: use correct callback for geo find queries
This commit is contained in:
parent
c7d23d18d0
commit
5e0c73bec7
20
lib/dao.js
20
lib/dao.js
|
@ -1531,6 +1531,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
|
|
||||||
const near = query && geo.nearFilter(query.where);
|
const near = query && geo.nearFilter(query.where);
|
||||||
const supportsGeo = !!connector.buildNearFilter;
|
const supportsGeo = !!connector.buildNearFilter;
|
||||||
|
let geoQueryObject;
|
||||||
|
|
||||||
if (near) {
|
if (near) {
|
||||||
if (supportsGeo) {
|
if (supportsGeo) {
|
||||||
|
@ -1558,8 +1559,10 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
queryGeo(ctx.query);
|
queryGeo(ctx.query);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// already handled
|
||||||
function queryGeo(query) {
|
return cb.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
function geoCallbackWithoutNotify(err, data) {
|
function geoCallbackWithoutNotify(err, data) {
|
||||||
const memory = new Memory();
|
const memory = new Memory();
|
||||||
const modelName = self.modelName;
|
const modelName = self.modelName;
|
||||||
|
@ -1580,7 +1583,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: apply "includes" and other transforms - see allCb below
|
// FIXME: apply "includes" and other transforms - see allCb below
|
||||||
memory.all(modelName, query, options, cb);
|
memory.all(modelName, geoQueryObject, options, allCb);
|
||||||
} else {
|
} else {
|
||||||
cb(null, []);
|
cb(null, []);
|
||||||
}
|
}
|
||||||
|
@ -1607,16 +1610,13 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
geoCallbackWithoutNotify(null, results);
|
geoCallbackWithoutNotify(null, results);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function queryGeo(query) {
|
||||||
|
geoQueryObject = query;
|
||||||
const geoCallback = options.notify === false ? geoCallbackWithoutNotify : geoCallbackWithNotify;
|
const geoCallback = options.notify === false ? geoCallbackWithoutNotify : geoCallbackWithNotify;
|
||||||
invokeConnectorMethod(connector, 'all', self, [{}], options, geoCallback);
|
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)) {
|
if (!err && Array.isArray(data)) {
|
||||||
async.map(data, function(item, next) {
|
async.map(data, function(item, next) {
|
||||||
const Model = self.lookupModel(item);
|
const Model = self.lookupModel(item);
|
||||||
|
@ -1709,7 +1709,7 @@ DataAccessObject.find = function find(query, options, cb) {
|
||||||
} else {
|
} else {
|
||||||
cb(err, data || []);
|
cb(err, data || []);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
if (options.notify === false) {
|
if (options.notify === false) {
|
||||||
invokeConnectorMethod(connector, 'all', self, [query], options, allCb);
|
invokeConnectorMethod(connector, 'all', self, [query], options, allCb);
|
||||||
|
|
|
@ -654,6 +654,7 @@ describe('basic-querying', function() {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
users.should.have.property('length', 3);
|
users.should.have.property('length', 3);
|
||||||
users[0].name.should.equal('John Lennon');
|
users[0].name.should.equal('John Lennon');
|
||||||
|
users[0].should.be.instanceOf(User);
|
||||||
users[0].addressLoc.should.not.be.null();
|
users[0].addressLoc.should.not.be.null();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -677,6 +678,7 @@ describe('basic-querying', function() {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
users.should.have.property('length', 2);
|
users.should.have.property('length', 2);
|
||||||
users[0].name.should.equal('John Lennon');
|
users[0].name.should.equal('John Lennon');
|
||||||
|
users[0].should.be.instanceOf(User);
|
||||||
users[0].addressLoc.should.not.be.null();
|
users[0].addressLoc.should.not.be.null();
|
||||||
users[0].vip.should.be.true();
|
users[0].vip.should.be.true();
|
||||||
done();
|
done();
|
||||||
|
@ -708,6 +710,7 @@ describe('basic-querying', function() {
|
||||||
if (err) done(err);
|
if (err) done(err);
|
||||||
users.should.have.property('length', 1);
|
users.should.have.property('length', 1);
|
||||||
users[0].name.should.equal('John Lennon');
|
users[0].name.should.equal('John Lennon');
|
||||||
|
users[0].should.be.instanceOf(User);
|
||||||
users[0].addressLoc.should.not.be.null();
|
users[0].addressLoc.should.not.be.null();
|
||||||
users[0].vip.should.be.true();
|
users[0].vip.should.be.true();
|
||||||
users[0].order.should.equal(2);
|
users[0].order.should.equal(2);
|
||||||
|
@ -738,6 +741,7 @@ describe('basic-querying', function() {
|
||||||
users.should.have.property('length', 2);
|
users.should.have.property('length', 2);
|
||||||
users[0].addressLoc.should.not.be.null();
|
users[0].addressLoc.should.not.be.null();
|
||||||
users[0].name.should.equal('Paul McCartney');
|
users[0].name.should.equal('Paul McCartney');
|
||||||
|
users[0].should.be.instanceOf(User);
|
||||||
users[1].addressLoc.should.not.equal(null);
|
users[1].addressLoc.should.not.equal(null);
|
||||||
users[1].name.should.equal('John Lennon');
|
users[1].name.should.equal('John Lennon');
|
||||||
done();
|
done();
|
||||||
|
@ -775,6 +779,7 @@ describe('basic-querying', function() {
|
||||||
users.should.have.property('length', 1);
|
users.should.have.property('length', 1);
|
||||||
users[0].addressLoc.should.not.be.null();
|
users[0].addressLoc.should.not.be.null();
|
||||||
users[0].name.should.equal('John Lennon');
|
users[0].name.should.equal('John Lennon');
|
||||||
|
users[0].should.be.instanceOf(User);
|
||||||
users[0].vip.should.be.true();
|
users[0].vip.should.be.true();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue