Fix vendor and category page loading issues
This commit is contained in:
@@ -94,17 +94,29 @@ router.get('/', async (req, res) => {
|
||||
SELECT
|
||||
COUNT(DISTINCT c.id) as totalCategories,
|
||||
COUNT(DISTINCT CASE WHEN cm.status = 'active' THEN c.id END) as activeCategories,
|
||||
SUM(cm.total_value) as totalValue,
|
||||
AVG(cm.avg_margin) as avgMargin,
|
||||
AVG(cm.growth_rate) as avgGrowth
|
||||
COALESCE(SUM(cm.total_value), 0) as totalValue,
|
||||
COALESCE(ROUND(AVG(NULLIF(cm.avg_margin, 0)), 1), 0) as avgMargin,
|
||||
COALESCE(ROUND(AVG(NULLIF(cm.growth_rate, 0)), 1), 0) as avgGrowth
|
||||
FROM categories c
|
||||
LEFT JOIN category_metrics cm ON c.id = cm.category_id
|
||||
`);
|
||||
|
||||
res.json({
|
||||
categories,
|
||||
categories: categories.map(cat => ({
|
||||
...cat,
|
||||
product_count: parseInt(cat.product_count || 0),
|
||||
total_value: parseFloat(cat.total_value || 0),
|
||||
avg_margin: parseFloat(cat.avg_margin || 0),
|
||||
turnover_rate: parseFloat(cat.turnover_rate || 0),
|
||||
growth_rate: parseFloat(cat.growth_rate || 0)
|
||||
})),
|
||||
parentCategories: parentCategories.map(p => p.parent_category),
|
||||
stats: stats[0],
|
||||
stats: {
|
||||
...stats[0],
|
||||
totalValue: parseFloat(stats[0].totalValue || 0),
|
||||
avgMargin: parseFloat(stats[0].avgMargin || 0),
|
||||
avgGrowth: parseFloat(stats[0].avgGrowth || 0)
|
||||
},
|
||||
pagination: {
|
||||
total: countResult[0].total,
|
||||
pages: Math.ceil(countResult[0].total / limit),
|
||||
|
||||
Reference in New Issue
Block a user