mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-30 08:52:38 +00:00
initial commit
This commit is contained in:
@@ -29,12 +29,20 @@ const rendererConditions = (legacy, v3)=>{
|
||||
return {}; // If all renderers selected, renderer field not needed in query for speed
|
||||
};
|
||||
|
||||
const sortConditions = (sort, dir) => {
|
||||
return {
|
||||
[sort]: dir === 'asc' ? 1 : -1
|
||||
};
|
||||
}
|
||||
|
||||
const findBrews = async (req, res)=>{
|
||||
const title = req.query.title || '';
|
||||
const author = req.query.author || '';
|
||||
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
||||
const count = Math.max(parseInt(req.query.count) || 20, 10);
|
||||
const skip = (page - 1) * count;
|
||||
const sort = req.query.sort || 'title';
|
||||
const dir = req.query.dir || 'asc';
|
||||
|
||||
const combinedQuery = {
|
||||
$and : [
|
||||
@@ -55,6 +63,7 @@ const findBrews = async (req, res)=>{
|
||||
|
||||
await HomebrewModel.find(combinedQuery, projection)
|
||||
.skip(skip)
|
||||
.sort(sortConditions(sort, dir))
|
||||
.limit(count)
|
||||
.maxTimeMS(5000)
|
||||
.exec()
|
||||
|
||||
Reference in New Issue
Block a user