0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-06 18:42:40 +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

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