-
Notifications
You must be signed in to change notification settings - Fork 248
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
geoWithin support #101
base: master
Are you sure you want to change the base?
geoWithin support #101
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ var methods = ['get', 'post', 'put', 'delete'], // All HTTP methods, PATCH not c | |
}, | ||
'in': query('in'), | ||
'nin': query('nin'), | ||
'within': query('within'), | ||
}); | ||
defaults = function() { | ||
return { | ||
|
@@ -357,9 +358,15 @@ function preprocess(req, res, next) { | |
} | ||
|
||
function query(key) { | ||
return function(val, query) { | ||
return query[key](val); | ||
}; | ||
if (key === 'within') { | ||
return function(val, query) { | ||
return query[key].apply(query, val); | ||
}; | ||
} else { | ||
return function(val, query) { | ||
return query[key](val); | ||
}; | ||
} | ||
} | ||
|
||
function haveOneModel(req) { | ||
|
@@ -465,6 +472,18 @@ function filterable(props, subfilters) { | |
data = data.split(','); | ||
} | ||
|
||
if (filter_func === 'within') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can leverage the existing condition for 'in' and 'nin' i.e.
Actually, now that I look at this... this should all be done in
I hope that makes sense. That way, the preprocessing on input happens in one place There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Within function requires here multiple coordinate pairs (2 for square search areas or more for polygons). |
||
if (!Array.isArray(data)) { | ||
data = [data]; | ||
} | ||
|
||
data = _.map(data, function(item) { | ||
return _.map(item.split(','), function(item) { | ||
return parseFloat(item); | ||
}); | ||
}); | ||
} | ||
|
||
return subfilters[filter_func](data, quer.where(field[0])); | ||
}, | ||
contains: function(key, quer) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this special case really necessary? Seems redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because within function requires multiple arguments. For square area there will be 2 arguments, for polygons more.