Fixes for blank data
parent
7cef58dae3
commit
e7cbed7132
|
@ -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',
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
<div class="card-body text-center">
|
||||
<h5 class="card-title">Top products sold</h5>
|
||||
<ul class="list-unstyled">
|
||||
{{#if dashboardData.topProducts}}
|
||||
{{#each dashboardData.topProducts}}
|
||||
<li class="media my-4 align-middle">
|
||||
<img src="{{this.productImage}}" class="col-2 mr-3 img-fluid" alt="">
|
||||
|
@ -62,6 +63,9 @@
|
|||
</div>
|
||||
</li>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
<h5 class="mt-3 mb-1 text-danger">Nothing to see yet. Do some orders.</h5>
|
||||
{{/if}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue