From e2b38829f2ac7db54b551f5019cd63a8f4ed87bf Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 7 Apr 2025 08:25:42 +1200 Subject: [PATCH] Refactor /api/lock/count --- server/admin.api.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/server/admin.api.js b/server/admin.api.js index 96a21c8a7..9207daf71 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -165,21 +165,18 @@ router.get('/admin/stats', mw.adminOnly, async (req, res)=>{ }); router.get('/api/lock/count', mw.adminOnly, async (req, res)=>{ - try { - const countLocksQuery = { - lock : { $exists: true } - }; - const count = await HomebrewModel.countDocuments(countLocksQuery) - .then((result)=>{ - return result; - }); - return res.json({ - count + + const countLocksQuery = { + lock : { $exists: true } + }; + const count = await HomebrewModel.countDocuments(countLocksQuery) + .catch((error)=>{ + console.error(error); + return res.json({ status: 'ERROR', detail: 'Unable to get lock count', error }); }); - } catch (error) { - console.error(error); - return res.json({ status: 'ERROR', detail: 'Unable to get lock count', error }); - } + + return res.json({ count }); + }); router.post('/api/lock/:id', mw.adminOnly, async (req, res)=>{