Optimize product detail analytics loading
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 43s

This commit is contained in:
Cauê Faleiros
2026-06-22 15:49:40 -03:00
parent 3cd4bfc426
commit 62e0239ee4
7 changed files with 280 additions and 60 deletions

View File

@@ -5,6 +5,7 @@ const {
getClientDetailsAnalytics,
getDashboardAnalytics,
getProductAnalytics,
getProductDetailsAnalytics,
getRfmAnalytics
} = require('../services/analyticsService');
@@ -33,6 +34,21 @@ router.get('/analytics/products', verifyToken, async (req, res) => {
}
});
router.get('/analytics/products/:productId/details', verifyToken, async (req, res) => {
try {
const details = await getProductDetailsAnalytics(req.params.productId, getRange(req.query));
if (!details) {
res.status(404).json({ error: 'Product not found' });
return;
}
res.json(details);
} catch (error) {
console.error('Error fetching product details analytics:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
router.get('/analytics/clients', verifyToken, async (req, res) => {
try {
res.json(await getClientAnalytics(getRange(req.query)));