mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 06:32:39 +00:00
Fixing edge cases in the search tests
This commit is contained in:
@@ -21,29 +21,31 @@ module.exports = (Brew) => {
|
||||
return cmds.search(query, opts, fullAccess);
|
||||
},
|
||||
|
||||
search : (queryObj={}, opts={}, fullAccess = true) => {
|
||||
const pagination = _.defaults(opts.pagination, {
|
||||
search : (queryObj={}, options={}, fullAccess = true) => {
|
||||
const opts = _.merge({
|
||||
limit : 25,
|
||||
page : 0
|
||||
});
|
||||
const sorting = _.defaults(opts.sorting, {
|
||||
'views' : 1
|
||||
});
|
||||
page : 0,
|
||||
sort : {}
|
||||
}, options);
|
||||
|
||||
let filter = {
|
||||
text : 0
|
||||
};
|
||||
|
||||
if(!fullAccess){
|
||||
filter.editId = 0;
|
||||
queryObj.published = false;
|
||||
queryObj.published = true;
|
||||
}
|
||||
|
||||
const searchQuery = Brew
|
||||
.find(queryObj)
|
||||
.sort(sorting)
|
||||
.sort(opts.sort)
|
||||
.select(filter)
|
||||
.limit(pagination.limit)
|
||||
.skip(pagination.page * pagination.limit)
|
||||
.limit(opts.limit)
|
||||
.skip(opts.page * opts.limit)
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
const countQuery = Brew.count(queryObj).exec();
|
||||
|
||||
return Promise.all([searchQuery, countQuery])
|
||||
|
||||
@@ -16,7 +16,7 @@ const Middleware = {
|
||||
return next();
|
||||
},
|
||||
admin : (req, res, next) => {
|
||||
if(req.query.admin_key === config.get('admin:key')){
|
||||
if(req.headers['x-homebrew-admin'] === config.get('admin:key')){
|
||||
req.admin = true;
|
||||
}
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user