0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-22 09:37:53 +00:00

Tidy findBrews

This commit is contained in:
Trevor Buckner
2024-09-03 23:11:10 -04:00
parent 590318ff1d
commit 56185e2a1c

View File

@@ -33,20 +33,15 @@ 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 mincount = 10;
const count = Math.max(parseInt(req.query.count) || 20, mincount);
const count = Math.max(parseInt(req.query.count) || 20, 10);
const skip = (page - 1) * count;
const rendererQuery = rendererConditions(req.query.legacy, req.query.v3);
const titleQuery = titleConditions(title);
const authorQuery = authorConditions(author);
const combinedQuery = {
$and: [
{ published: true },
rendererQuery,
titleQuery,
authorQuery,
rendererConditions(req.query.legacy, req.query.v3),
titleConditions(title),
authorConditions(author)
],
};
@@ -55,7 +50,7 @@ const findBrews = async (req, res) => {
googleId : 0,
text : 0,
textBin : 0,
version: 0,
version : 0
};
await HomebrewModel.find(combinedQuery, projection)