Skip to content

Commit

Permalink
add findWithRegex
Browse files Browse the repository at this point in the history
  • Loading branch information
birm committed Aug 21, 2023
1 parent 0d8d819 commit e7f5417
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var HANDLERS = {
"dataEnforce": auth.dataEnforce,
"monitorCheck": monitor.check,
"mongoFind": dataHandlers.General.find,
"mongoFindWithRegex": dataHandlers.General.findWithRegex,
"mongoAdd": dataHandlers.General.add,
"mongoUpdate": dataHandlers.General.update,
"mongoDelete": dataHandlers.General.delete,
Expand Down
15 changes: 15 additions & 0 deletions handlers/dataHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ General.find = function(db, collection) {
};
};

General.findWithRegex = function(db, collection) {
return function(req, res, next) {
var query = req.query;
for (let i in query) {
if (query.hasOwnProperty(i)) {
query[i] = new RegExp(query[i], 'i'); // case insensitive search
}
}
mongoDB.find(db, collection, query).then((x) => {
req.data = x;
next();
}).catch((e) => next(e));
};
};

General.get = function(db, collection) {
return function(req, res, next) {
var query = req.query;
Expand Down

0 comments on commit e7f5417

Please sign in to comment.