Added getAllManufacturingIndex API

This commit is contained in:
unknown 2025-12-24 12:55:37 +05:30
parent 67ec8f6214
commit 2ef1dc8be4
3 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,43 @@
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" });
}
};

View File

@ -0,0 +1,67 @@
module.exports = (sequelize, DataTypes) => {
const ManufacturingIpi = sequelize.define("manufacturing_ipi", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
year: {
type: DataTypes.INTEGER,
allowNull: false,
},
month: {
type: DataTypes.INTEGER,
allowNull: false,
},
month_name: {
type: DataTypes.STRING,
allowNull: false,
},
reference_date: {
type: DataTypes.DATEONLY,
allowNull: false,
},
total_weight: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
weighted_index_sum: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
manufacturing_index: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
},
mom_change: {
type: DataTypes.DECIMAL(12, 2),
allowNull: true,
},
yoy_change: {
type: DataTypes.DECIMAL(12, 2),
allowNull: true,
},
status: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'Completed',
},
generated_on: {
type: DataTypes.DATE,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
},
updated_at: {
type: DataTypes.DATE,
allowNull: true,
},
}, {
tableName: "manufacturing_ipi",
timestamps: false,
});
return ManufacturingIpi;
};

View File

@ -17,6 +17,7 @@ const ConfigController = require("../controllers/config.controller");
const dashboardController = require("../controllers/dashboard.controller");
const notificationTemplateController = require("../controllers/notificationTemplate.controller");
const quarterlyWindowsController = require("../controllers/quarterlyWindowsConfiguration.controller");
const ManufacturingIpiController = require("../controllers/manufacturingIPI.controller")
const fs = require("fs");
const path = require("path");
const multer = require("multer");
@ -2992,6 +2993,26 @@ router.get("/establishment/download-sample-file",[verifySignature, verifyToken],
*/
router.get("/unit_master_download_sample_file",[verifySignature, verifyToken], unitMasterController.downloadUnitMasterFile);
/**
* @swagger
* /api/manufacturing/getManufacturingIndex:
* get:
* summary: Get all Manufacturing IPI Index list
* tags: [ManufacturingIpi]
* security:
* - appSignature: []
* - CSRF: []
* cookieAuth: [] # or bearerAuth: [] if you use Authorization header
* responses:
* 200:
* description: ManufacturingIpi Index details fetched successfully
* 404:
* description: Not found
* 500:
* description: Server error
*/
router.get("/manufacturing/getManufacturingIndex",[verifySignature, verifyToken], ManufacturingIpiController.getAllManufacturingIndexDetails);