mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 20:23:39 +00:00
rest of the suggested changes
This commit is contained in:
@@ -174,6 +174,8 @@ const errorIndex = (props)=>{
|
|||||||
|
|
||||||
'90' : dedent` An unexpected error occurred while looking for these brews.
|
'90' : dedent` An unexpected error occurred while looking for these brews.
|
||||||
Try again in a few minutes.`,
|
Try again in a few minutes.`,
|
||||||
|
|
||||||
|
'91' : dedent` An unexpected error occurred while trying to get the total of brews.`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const HomebrewModel = require('./homebrew.model.js').model;
|
|||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
const buildTitleConditions = (title) => {
|
const titleConditions = (title) => {
|
||||||
if (!title) return {};
|
if (!title) return {};
|
||||||
return {
|
return {
|
||||||
$text: {
|
$text: {
|
||||||
@@ -14,12 +14,12 @@ const buildTitleConditions = (title) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAuthorConditions = (author) => {
|
const authorConditions = (author) => {
|
||||||
if (!author) return {};
|
if (!author) return {};
|
||||||
return { authors: author };
|
return { authors: author };
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildRendererConditions = (legacy, v3) => {
|
const rendererConditions = (legacy, v3) => {
|
||||||
const brewsQuery = {};
|
const brewsQuery = {};
|
||||||
|
|
||||||
if (legacy === 'true' && v3 !== 'true') {
|
if (legacy === 'true' && v3 !== 'true') {
|
||||||
@@ -40,9 +40,9 @@ const findBrews = async (req, res) => {
|
|||||||
const count = Math.max(parseInt(req.query.count) || 20, mincount);
|
const count = Math.max(parseInt(req.query.count) || 20, mincount);
|
||||||
const skip = (page - 1) * count;
|
const skip = (page - 1) * count;
|
||||||
|
|
||||||
const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3);
|
const brewsQuery = rendererConditions(req.query.legacy, req.query.v3);
|
||||||
const titleConditions = buildTitleConditions(title);
|
const titleConditions = titleConditions(title);
|
||||||
const authorConditions = buildAuthorConditions(author);
|
const authorConditions = authorConditions(author);
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and: [
|
$and: [
|
||||||
@@ -84,9 +84,9 @@ const findTotal = async (req, res) => {
|
|||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const author = req.query.author || '';
|
const author = req.query.author || '';
|
||||||
|
|
||||||
const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3);
|
const brewsQuery = rendererConditions(req.query.legacy, req.query.v3);
|
||||||
const titleConditions = buildTitleConditions(title);
|
const titleConditions = titleConditions(title);
|
||||||
const authorConditions = buildAuthorConditions(author);
|
const authorConditions = authorConditions(author);
|
||||||
|
|
||||||
const combinedQuery = {
|
const combinedQuery = {
|
||||||
$and: [
|
$and: [
|
||||||
@@ -99,17 +99,12 @@ const findTotal = async (req, res) => {
|
|||||||
|
|
||||||
await HomebrewModel.countDocuments(combinedQuery)
|
await HomebrewModel.countDocuments(combinedQuery)
|
||||||
.then((totalBrews) => {
|
.then((totalBrews) => {
|
||||||
console.log(
|
console.log(`when returning, the total of brews is ${totalBrews} for the query ${JSON.stringify(combinedQuery)}`);
|
||||||
'when returning, the total of brews is ',
|
|
||||||
totalBrews,
|
|
||||||
'for the query',
|
|
||||||
JSON.stringify(combinedQuery)
|
|
||||||
);
|
|
||||||
res.json({ totalBrews });
|
res.json({ totalBrews });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
throw {...err, message: "Error finding brews in Vault search", HBErrorCode: 90};
|
throw {...err, message: "Error finding brews in Vault search findTotal function", HBErrorCode: 91};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user