Commit eada4675 authored by anton's avatar anton
Browse files

Support $search and $regex operators in find

parent 6197be51
// Application hooks that run for every service
const searchRegex = require('./hooks/search-regex')
module.exports = {
before: {
all: [],
find: [],
find: [searchRegex()],
get: [],
create: [],
update: [],
......
function searchRegex () {
return function (hook) {
const query = hook.params.query
const transform = query => {
for (let field in query) {
if (Array.isArray(query[field])) {
for (let i in query[field]) {
query[field][i] = transform(query[field][i])
}
}
else if (query[field] && query[field].$search && field.indexOf('$') === -1) {
query[field] = { $regex: new RegExp(query[field].$search, 'ig') }
}
}
return query
}
hook.params.query = transform(query)
return hook
}
}
module.exports = searchRegex
......@@ -4,7 +4,8 @@ const conditionalDbService = require('../conditional-db-service')
module.exports = function (app) {
const options = {
paginate: app.get('paginate')
paginate: app.get('paginate'),
whitelist: ['$regex', '$search', '$elemMatch']
}
const Annotations = conditionalDbService(app, 'annotations')
......
......@@ -4,7 +4,8 @@ const conditionalDbService = require('../conditional-db-service')
module.exports = function (app) {
const options = {
paginate: app.get('paginate')
paginate: app.get('paginate'),
whitelist: ['$regex', '$search', '$elemMatch']
}
const Maps = conditionalDbService(app, 'maps')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment