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) => {
|
||||
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",
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user