0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-14 06:22:40 +00:00

All tests should be done, phew

This commit is contained in:
Scott Tolksdorf
2017-01-28 12:25:26 -05:00
parent 26bcb3395a
commit 75111acefb
6 changed files with 289 additions and 117 deletions

View File

@@ -3,30 +3,35 @@ const _ = require('lodash');
module.exports = (Brew) => {
const cmds = {
termSearch : (terms='', opts, fullAccess) => {
const query = {$text: {
//Wrap terms in quotes to perform an AND operation
$search: _.map(terms.split(' '), (term)=>{
return `\"${term}\"`;
}).join(' '),
$caseSensitive : false
}};
let query = {};
if(terms){
query = {$text: {
//Wrap terms in quotes to perform an AND operation
$search: _.map(terms.split(' '), (term)=>{
return `\"${term}\"`;
}).join(' '),
$caseSensitive : false
}};
}
return cmds.search(query, opts, fullAccess);
},
userSearch : (username, opts, fullAccess) => {
userSearch : (username, fullAccess) => {
const query = {
authors : username
};
return cmds.search(query, opts, fullAccess);
return cmds.search(query, {}, fullAccess);
},
search : (queryObj={}, options={}, fullAccess = true) => {
const opts = _.merge({
limit : 25,
page : 0,
sort : {}
sort : {}
}, options);
opts.limit = _.toNumber(opts.limit);
opts.page = _.toNumber(opts.page);
let filter = {
text : 0