From e7cbed71329c51b906bdc5705efd9c38d328a06c Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Mon, 30 Dec 2019 23:06:06 +1030 Subject: [PATCH] Fixes for blank data --- routes/admin.js | 15 +++++++++------ views/dashboard.hbs | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/routes/admin.js b/routes/admin.js index c18e403..7860b59 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -151,10 +151,7 @@ router.get('/admin/dashboard', restrict, async (req, res) => { _id: '$o.v.productId', title: { $last: '$o.v.title' }, productImage: { $last: '$o.v.productImage' }, - count: - { - $sum: '$o.v.quantity' - } + count: { $sum: '$o.v.quantity' } } }, { $sort: { count: -1 } }, { $limit: 5 } @@ -162,8 +159,14 @@ router.get('/admin/dashboard', restrict, async (req, res) => { }; // Fix aggregate data - dashboardData.ordersAmount = dashboardData.ordersAmount[0].sum; - dashboardData.productsSold = dashboardData.productsSold[0].sum; + if(dashboardData.ordersAmount.length > 0){ + dashboardData.ordersAmount = dashboardData.ordersAmount[0].sum; + } + if(dashboardData.productsSold.length > 0){ + dashboardData.productsSold = dashboardData.productsSold[0].sum; + }else{ + dashboardData.productsSold = 0; + } res.render('dashboard', { title: 'Cart dashboard', diff --git a/views/dashboard.hbs b/views/dashboard.hbs index fc3978d..b8de9f2 100644 --- a/views/dashboard.hbs +++ b/views/dashboard.hbs @@ -53,6 +53,7 @@
Top products sold
{{/each}} + {{else}} +
Nothing to see yet. Do some orders.
+ {{/if}}