Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/allow searching null values #179

Merged
merged 2 commits into from
Oct 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/events-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = function (harvesterApp) {
var processWithHandlerT = throttle(processWithHandler, {
// call a maximum of 100 times per 1s window
window: 1,
limit: 100
limit: parseInt(_.get(harvesterApp, 'options.eventsReaderThrottleLimit'), 10) || 100
});


Expand Down
8 changes: 6 additions & 2 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,13 @@ function route(harvester, name, model, schema, routeOptions) {

//TODO: links.->"" is a mongodb storage issue, and should be in the mongodb adapter rather than here.
//allow multiple ids or other query params at the same time.
_.each(query, function (val, key, list) {
_.each(query, function (val, key) {
if (_.isString(val) && val.indexOf(',') != -1) {
query[key] = {$in: val.split(',')};
query[key] = {
$in: val.split(',').map(function (item) {
return item.length === 0 ? null : item;
})
};
}
});

Expand Down
1 change: 1 addition & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var config = require('./config.js');
function configureApp(harvesterApp) {
harvesterApp.resource('person', {
name: Joi.string().required().description('name'),
nickname: Joi.string().description('nickname'),
appearances: Joi.number().required().description('appearances'),
links: {
pets: ['pet'],
Expand Down
21 changes: 21 additions & 0 deletions test/filters.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var _ = require('lodash');
var should = require('should');
var request = require('supertest');
var Promise = require('bluebird');
Expand All @@ -22,6 +23,26 @@ describe("filters", function () {
done();
});
});
it("should allow top-level resource filtering based on empty property", function (done) {
request(config.baseUrl).get('/people?nickname=,').expect('Content-Type', /json/).expect(200).end(function (error, response) {
should.not.exist(error);
var body = JSON.parse(response.text);
body.people.length.should.equal(2);
body.people.forEach(function (person) {
person.should.not.have.property('nickname');
});
done();
});
});
it("should allow top-level resource filtering based on empty property", function (done) {
request(config.baseUrl).get('/people?nickname=Pocahontas,').expect('Content-Type', /json/).expect(200).end(function (error, response) {
should.not.exist(error);
var body = JSON.parse(response.text);
body.people.length.should.equal(3);
_.map(body.people, 'nickname').sort().should.eql(['Pocahontas', undefined, undefined]);
done();
});
});

it("should allow top-level resource filtering based on a numeric value", function (done) {
request(config.baseUrl).get('/people?appearances=1934').expect('Content-Type', /json/).expect(200).end(function (error, response) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (function () {
{
"id": "600274a7-3862-45d7-8fca-e558cea1cf6d",
"name": "Catbert",
"nickname": "Pocahontas",
"appearances": 205
}
];
Expand Down