43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
const db = require("../models");
|
|
const ManufacturingIpi = db.ManufacturingIpi;
|
|
const logger = require("../services/logger");
|
|
|
|
const formatDecimal = (value) => {
|
|
if (value === null || value === undefined || value === '' || value === 0) {
|
|
return "0.00";
|
|
}
|
|
return parseFloat(value).toFixed(2);
|
|
};
|
|
|
|
exports.getAllManufacturingIndexDetails = async (req, res) => {
|
|
try {
|
|
const rawData = await ManufacturingIpi.findAll({
|
|
order: [["created_at", "DESC"]],
|
|
});
|
|
|
|
// Format decimal fields
|
|
const data = rawData.map(item => {
|
|
const plainItem = item.get({ plain: true });
|
|
return {
|
|
...plainItem,
|
|
total_weight: formatDecimal(plainItem.total_weight),
|
|
weighted_index_sum: formatDecimal(plainItem.weighted_index_sum),
|
|
manufacturing_index: formatDecimal(plainItem.manufacturing_index),
|
|
mom_change: formatDecimal(plainItem.mom_change),
|
|
yoy_change: formatDecimal(plainItem.yoy_change),
|
|
};
|
|
});
|
|
|
|
logger.info(`getAllManufacturingIndexDetails API: Fetched ${data.length} manufacturing index records successfully`);
|
|
|
|
res.status(200).send({
|
|
status: "success",
|
|
message: "Fetched successfully",
|
|
data: data
|
|
});
|
|
|
|
} catch (error) {
|
|
logger.error(`getAllManufacturingIndexDetails API: ${error.message}`);
|
|
res.status(500).send({ status: "failed", message: "Internal server error" });
|
|
}
|
|
}; |