mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 20:42:43 +00:00
Lint clean up
This commit is contained in:
@@ -3,49 +3,49 @@ const router = require('express').Router();
|
||||
const asyncHandler = require('express-async-handler');
|
||||
|
||||
const archive = {
|
||||
archiveApi: router,
|
||||
/* Searches for matching title, also attempts to partial match */
|
||||
findBrews: async (req, res, next) => {
|
||||
try {
|
||||
const title = req.query.title || '';
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
console.log('try:',page);
|
||||
const pageSize = 10; // Set a default page size
|
||||
const skip = (page - 1) * pageSize;
|
||||
archiveApi : router,
|
||||
/* Searches for matching title, also attempts to partial match */
|
||||
findBrews : async (req, res, next)=>{
|
||||
try {
|
||||
const title = req.query.title || '';
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
console.log('try:', page);
|
||||
const pageSize = 10; // Set a default page size
|
||||
const skip = (page - 1) * pageSize;
|
||||
|
||||
const titleQuery = {
|
||||
title: { $regex: decodeURIComponent(title), $options: 'i' },
|
||||
published: true
|
||||
};
|
||||
const titleQuery = {
|
||||
title : { $regex: decodeURIComponent(title), $options: 'i' },
|
||||
published : true
|
||||
};
|
||||
|
||||
const projection = {
|
||||
editId: 0,
|
||||
googleId: 0,
|
||||
text: 0,
|
||||
textBin: 0,
|
||||
};
|
||||
const projection = {
|
||||
editId : 0,
|
||||
googleId : 0,
|
||||
text : 0,
|
||||
textBin : 0,
|
||||
};
|
||||
|
||||
const brews = await HomebrewModel.find(titleQuery, projection)
|
||||
const brews = await HomebrewModel.find(titleQuery, projection)
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.maxTimeMS(5000)
|
||||
.exec();
|
||||
|
||||
if (!brews || brews.length === 0) {
|
||||
// No published documents found with the given title
|
||||
return res.status(404).json({ error: 'Published documents not found' });
|
||||
}
|
||||
if(!brews || brews.length === 0) {
|
||||
// No published documents found with the given title
|
||||
return res.status(404).json({ error: 'Published documents not found' });
|
||||
}
|
||||
|
||||
const totalDocuments = await HomebrewModel.countDocuments(title);
|
||||
const totalDocuments = await HomebrewModel.countDocuments(title);
|
||||
|
||||
const totalPages = Math.ceil(totalDocuments / pageSize);
|
||||
const totalPages = Math.ceil(totalDocuments / pageSize);
|
||||
|
||||
return res.json({ brews, page, totalPages});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
return res.json({ brews, page, totalPages });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
router.get('/archive', asyncHandler(archive.findBrews));
|
||||
|
||||
Reference in New Issue
Block a user