0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 05:22:40 +00:00

inital commit

This commit is contained in:
Víctor Losada Hernández
2024-01-23 08:09:17 +01:00
parent 62e679571e
commit 0243b5f491

View File

@@ -55,13 +55,26 @@ router.post('/admin/cleanup', mw.adminOnly, (req, res)=>{
}); });
/* Searches for matching edit or share id, also attempts to partial match */ /* Searches for matching edit or share id, also attempts to partial match */
router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{
HomebrewModel.findOne({ $or : [ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => {
{ editId: { '$regex': req.params.id, '$options': 'i' } }, try {
{ shareId: { '$regex': req.params.id, '$options': 'i' } }, const brew = await HomebrewModel.findOne({
] }).exec((err, brew)=>{ $or: [
{ editId: { $regex: req.params.id, $options: 'i' } },
{ shareId: { $regex: req.params.id, $options: 'i' } },
]
}).exec();
if (!brew) {
// No document found
return res.status(404).json({ error: 'Document not found' });
}
return res.json(brew); return res.json(brew);
}); } catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
}
}); });
/* Find 50 brews that aren't compressed yet */ /* Find 50 brews that aren't compressed yet */
@@ -91,14 +104,37 @@ router.put('/admin/compress/:id', (req, res)=>{
}); });
}); });
router.get('/admin/stats', mw.adminOnly, (req, res)=>{ router.get('/admin/stats', mw.adminOnly, async (req, res) => {
HomebrewModel.count({}, (err, count)=>{ try {
const totalBrewsCount = await HomebrewModel.countDocuments({});
const publishedBrewsCount = await HomebrewModel.countDocuments({ published: true });
return res.json({ return res.json({
totalBrews : count totalBrews: totalBrewsCount,
}); totalPublishedBrews: publishedBrewsCount
}); });
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
}
}); });
/*
router.get('/admin/stats', mw.adminOnly, async (req, res) => {
try {
const count = await HomebrewModel.countDocuments({});
return res.json({
totalBrews: count
});
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
}
});
*/
router.get('/admin', mw.adminOnly, (req, res)=>{ router.get('/admin', mw.adminOnly, (req, res)=>{
templateFn('admin', { templateFn('admin', {
url : req.originalUrl url : req.originalUrl