0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +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,15 +55,28 @@ router.post('/admin/cleanup', mw.adminOnly, (req, res)=>{
});
/* 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 : [
{ editId: { '$regex': req.params.id, '$options': 'i' } },
{ shareId: { '$regex': req.params.id, '$options': 'i' } },
] }).exec((err, brew)=>{
return res.json(brew);
});
});
router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => {
try {
const brew = await HomebrewModel.findOne({
$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);
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
}
});
/* Find 50 brews that aren't compressed yet */
router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{
uncompressedBrewQuery.exec((err, objs)=>{
@@ -91,13 +104,36 @@ router.put('/admin/compress/:id', (req, res)=>{
});
});
router.get('/admin/stats', mw.adminOnly, (req, res)=>{
HomebrewModel.count({}, (err, count)=>{
return res.json({
totalBrews : count
});
});
router.get('/admin/stats', mw.adminOnly, async (req, res) => {
try {
const totalBrewsCount = await HomebrewModel.countDocuments({});
const publishedBrewsCount = await HomebrewModel.countDocuments({ published: true });
return res.json({
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)=>{
templateFn('admin', {