GWM : iip calculation
This commit is contained in:
parent
7be44b562d
commit
21d1d17bde
@ -61,27 +61,26 @@ exports.getAllManufacturingIndexDetails = async (req, res) => {
|
|||||||
|
|
||||||
exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => {
|
exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { year, month, quarter } = req.query;
|
const { year, quarter } = req.query;
|
||||||
|
|
||||||
// Validate parameters exist
|
// Validate parameters exist
|
||||||
if (!year || (!month && !quarter)) {
|
if (!year || !quarter) {
|
||||||
logger.warn('getManufacturingMonthlyOverview API: Missing required parameters');
|
logger.warn('getManufacturingMonthlyOverview API: Missing required parameters');
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
status: "failed",
|
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
|
// Sanitize and validate input - prevent SQL injection
|
||||||
const yearInt = parseInt(year, 10);
|
const yearInt = parseInt(year, 10);
|
||||||
const monthInt = month ? parseInt(month, 10) : null;
|
|
||||||
|
|
||||||
// Validate that parsing was successful
|
// Validate that parsing was successful
|
||||||
if (isNaN(yearInt) || (month && isNaN(monthInt))) {
|
if (isNaN(yearInt)) {
|
||||||
logger.warn(`getManufacturingMonthlyOverview API: Invalid input - year: ${year}, month: ${month}, quarter: ${quarter}`);
|
logger.warn(`getManufacturingMonthlyOverview API: Invalid input - year: ${year}, quarter: ${quarter}`);
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
status: "failed",
|
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)) {
|
if (!["Q1", "Q2", "Q3", "Q4"].includes(quarter)) {
|
||||||
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)) {
|
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
message: "Quarter must be one of Q1, Q2, Q3, Q4"
|
message: "Quarter must be one of Q1, Q2, Q3, Q4"
|
||||||
@ -111,7 +102,7 @@ exports.getManufacturingMonthlyOverviewByYearMonth = async (req, res) => {
|
|||||||
// Common where clause
|
// Common where clause
|
||||||
const whereClause = {
|
const whereClause = {
|
||||||
year: yearInt,
|
year: yearInt,
|
||||||
quarter: derivedQuarter
|
quarter
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch data from all tables in parallel
|
// 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({
|
res.status(200).send({
|
||||||
status: "success",
|
status: "success",
|
||||||
|
|||||||
@ -3272,7 +3272,7 @@ router.get("/manufacturing/getManufacturingIndex",[verifySignature, verifyToken]
|
|||||||
* @swagger
|
* @swagger
|
||||||
* /api/manufacturing/getManufacturingMonthlyOverview:
|
* /api/manufacturing/getManufacturingMonthlyOverview:
|
||||||
* get:
|
* get:
|
||||||
* summary: Get Manufacturing IPI Monthly Overview by year and month
|
* summary: Get Manufacturing IPI Overview by year and quarter
|
||||||
* tags: [ManufacturingIPI]
|
* tags: [ManufacturingIPI]
|
||||||
* security:
|
* security:
|
||||||
* - appSignature: []
|
* - appSignature: []
|
||||||
@ -3286,14 +3286,15 @@ router.get("/manufacturing/getManufacturingIndex",[verifySignature, verifyToken]
|
|||||||
* type: integer
|
* type: integer
|
||||||
* description: Year (e.g., 2025)
|
* description: Year (e.g., 2025)
|
||||||
* - in: query
|
* - in: query
|
||||||
* name: month
|
* name: quarter
|
||||||
* required: true
|
* required: true
|
||||||
* schema:
|
* schema:
|
||||||
* type: integer
|
* type: string
|
||||||
* description: Month (1-12)
|
* enum: [Q1, Q2, Q3, Q4]
|
||||||
|
* description: Quarter (Q1-Q4)
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: Manufacturing IPI Monthly Overview fetched successfully
|
* description: Manufacturing IPI Overview fetched successfully
|
||||||
* 400:
|
* 400:
|
||||||
* description: Invalid parameters
|
* description: Invalid parameters
|
||||||
* 404:
|
* 404:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user