From 770025da0473aadd15bf450b1112e5c8cc50480b Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sun, 21 Apr 2024 14:42:20 +1200 Subject: [PATCH] Add lock count route, update pipelines --- server/admin.api.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/server/admin.api.js b/server/admin.api.js index 5363ecc0..93c7771a 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -27,10 +27,12 @@ const mw = { }; const junkBrewPipeline = [ - { $match : { - updatedAt : { $lt: Moment().subtract(30, 'days').toDate() }, - lastViewed : { $lt: Moment().subtract(30, 'days').toDate() } - }}, + { $match : + { + updatedAt : { $lt: Moment().subtract(30, 'days').toDate() }, + lastViewed : { $lt: Moment().subtract(30, 'days').toDate() } + } + }, { $project: { textBinSize: { $binarySize: '$textBin' } } }, { $match: { textBinSize: { $lt: 140 } } }, { $limit: 100 } @@ -138,6 +140,31 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{ } }); +router.get('/admin/lock', mw.adminOnly, async (req, res)=>{ + try { + const countLocksPipeline = [ + { + $match : + { + 'lock.locked' : true, + }, + }, + { + $count : + 'count', + } + ]; + const totalLockCount = await HomebrewModel.getAggregate(countLocksPipeline); + const count = totalLockCount[0].count; + return res.json({ + count + }); + } catch (error) { + console.error(error); + return res.status(500).json({ error: 'Unable to get lock count' }); + } +}); + router.get('/admin', mw.adminOnly, (req, res)=>{ templateFn('admin', { url : req.originalUrl