Fix and restyle overstockmetrics and topoverstockedproducts, link products to backend

This commit is contained in:
2025-01-18 00:43:57 -05:00
parent 9759bac94f
commit 1b4447f886
4 changed files with 47 additions and 21 deletions

View File

@@ -357,7 +357,7 @@ router.get('/overstock/metrics', async (req, res) => {
SUM(total_excess_units) as total_excess_units,
SUM(total_excess_cost) as total_excess_cost,
SUM(total_excess_retail) as total_excess_retail,
CAST(JSON_ARRAYAGG(
CONCAT('[', GROUP_CONCAT(
JSON_OBJECT(
'category', category_name,
'products', overstocked_products,
@@ -365,7 +365,7 @@ router.get('/overstock/metrics', async (req, res) => {
'cost', total_excess_cost,
'retail', total_excess_retail
)
) AS JSON) as category_data
), ']') as category_data
FROM (
SELECT *
FROM category_overstock
@@ -378,10 +378,17 @@ router.get('/overstock/metrics', async (req, res) => {
// Format response with explicit type conversion
const response = {
overstockedProducts: parseInt(rows[0].total_overstocked) || 0,
excessUnits: parseInt(rows[0].total_excess_units) || 0,
excessCost: parseFloat(rows[0].total_excess_cost) || 0,
excessRetail: parseFloat(rows[0].total_excess_retail) || 0,
categoryData: rows[0].category_data ? JSON.parse(rows[0].category_data) : []
total_excess_units: parseInt(rows[0].total_excess_units) || 0,
total_excess_cost: parseFloat(rows[0].total_excess_cost) || 0,
total_excess_retail: parseFloat(rows[0].total_excess_retail) || 0,
category_data: rows[0].category_data ?
JSON.parse(rows[0].category_data).map(obj => ({
category: obj.category,
products: parseInt(obj.products) || 0,
units: parseInt(obj.units) || 0,
cost: parseFloat(obj.cost) || 0,
retail: parseFloat(obj.retail) || 0
})) : []
};
res.json(response);