From 21d1d17bde5681480c237cbb01a861082378c54d Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 29 Apr 2026 11:09:06 +0530 Subject: [PATCH] GWM : iip calculation --- .../manufacturingIPI.controller.js | 27 +++++++------------ app/routes/routes.js | 11 ++++---- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/controllers/manufacturingIPI.controller.js b/app/controllers/manufacturingIPI.controller.js index f8686cf..480b8dd 100644 --- a/app/controllers/manufacturingIPI.controller.js +++ b/app/controllers/manufacturingIPI.controller.js @@ -61,27 +61,26 @@ exports.getAllManufacturingIndexDetails = async (req, res) => { exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => { try { - const { year, month, quarter } = req.query; + const { year, quarter } = req.query; // Validate parameters exist - if (!year || (!month && !quarter)) { + if (!year || !quarter) { logger.warn('getManufacturingMonthlyOverview API: Missing required parameters'); return res.status(400).send({ status: "failed", - message: "Year and quarter (or month to derive quarter) are required" + message: "Year and quarter are required" }); } // Sanitize and validate input - prevent SQL injection const yearInt = parseInt(year, 10); - const monthInt = month ? parseInt(month, 10) : null; // Validate that parsing was successful - if (isNaN(yearInt) || (month && isNaN(monthInt))) { - logger.warn(`getManufacturingMonthlyOverview API: Invalid input - year: ${year}, month: ${month}, quarter: ${quarter}`); + if (isNaN(yearInt)) { + logger.warn(`getManufacturingMonthlyOverview API: Invalid input - year: ${year}, quarter: ${quarter}`); return res.status(400).send({ status: "failed", - message: "Year/month must be valid numbers" + message: "Year must be a valid number" }); } @@ -93,15 +92,7 @@ exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => { }); } - if (month && (monthInt < 1 || monthInt > 12)) { - return res.status(400).send({ - status: "failed", - message: "Month must be between 1 and 12" - }); - } - - const derivedQuarter = quarter || (monthInt <= 3 ? "Q1" : monthInt <= 6 ? "Q2" : monthInt <= 9 ? "Q3" : "Q4"); - if (!["Q1", "Q2", "Q3", "Q4"].includes(derivedQuarter)) { + if (!["Q1", "Q2", "Q3", "Q4"].includes(quarter)) { return res.status(400).send({ status: "failed", message: "Quarter must be one of Q1, Q2, Q3, Q4" @@ -111,7 +102,7 @@ exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => { // Common where clause const whereClause = { year: yearInt, - quarter: derivedQuarter + quarter }; // Fetch data from all tables in parallel @@ -190,7 +181,7 @@ exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => { }; }); - logger.info(`getManufacturingMonthlyOverview API: Successfully fetched data for year ${yearInt}, quarter ${derivedQuarter}`); + logger.info(`getManufacturingMonthlyOverview API: Successfully fetched data for year ${yearInt}, quarter ${quarter}`); res.status(200).send({ status: "success", diff --git a/app/routes/routes.js b/app/routes/routes.js index dc962b8..448ac1f 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -3272,7 +3272,7 @@ router.get("/manufacturing/getManufacturingIndex",[verifySignature, verifyToken] * @swagger * /api/manufacturing/getManufacturingMonthlyOverview: * get: - * summary: Get Manufacturing IPI Monthly Overview by year and month + * summary: Get Manufacturing IPI Overview by year and quarter * tags: [ManufacturingIPI] * security: * - appSignature: [] @@ -3286,14 +3286,15 @@ router.get("/manufacturing/getManufacturingIndex",[verifySignature, verifyToken] * type: integer * description: Year (e.g., 2025) * - in: query - * name: month + * name: quarter * required: true * schema: - * type: integer - * description: Month (1-12) + * type: string + * enum: [Q1, Q2, Q3, Q4] + * description: Quarter (Q1-Q4) * responses: * 200: - * description: Manufacturing IPI Monthly Overview fetched successfully + * description: Manufacturing IPI Overview fetched successfully * 400: * description: Invalid parameters * 404: