From 2d4c8f8b1123fae966c4613705b8feeadf750933 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 3 Feb 2026 11:48:53 +0530 Subject: [PATCH] GWM : Automation for Survey and iip calculation --- .../quarterlyWindowsConfiguration.model.js | 4 +++ app/services/scheduler.service.js | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/app/models/quarterlyWindowsConfiguration.model.js b/app/models/quarterlyWindowsConfiguration.model.js index 6b18573..6f1b566 100644 --- a/app/models/quarterlyWindowsConfiguration.model.js +++ b/app/models/quarterlyWindowsConfiguration.model.js @@ -55,6 +55,10 @@ module.exports = (sequelize, DataTypes) => { assigned: { type: DataTypes.INTEGER }, responded: { type: DataTypes.INTEGER }, not_responded: { type: DataTypes.INTEGER }, + ipi_calculated:{ + type: DataTypes.BOOLEAN, + defaultValue: false, + }, }, { tableName: "quarterly_windows_configuration_master", diff --git a/app/services/scheduler.service.js b/app/services/scheduler.service.js index 00e5ee2..4b4b184 100644 --- a/app/services/scheduler.service.js +++ b/app/services/scheduler.service.js @@ -41,6 +41,7 @@ class AutomatedSchedulerService { end_date, start_date FROM quarterly_windows_configuration_master + WHERE ipi_calculated = 0 ORDER BY year DESC, CASE quarter WHEN 'Q1' THEN 1 @@ -145,6 +146,28 @@ class AutomatedSchedulerService { } } + /** + * Update ipi_calculated flag in quarterly_windows_configuration_master + */ + async updateIPICalculatedFlag(year, quarter) { + const connection = await this.pool.getConnection(); + try { + const query = ` + UPDATE quarterly_windows_configuration_master + SET ipi_calculated = 1 + WHERE year = ? AND quarter = ? + `; + + await connection.query(query, [year, quarter]); + console.log(`[${new Date().toISOString()}] Updated ipi_calculated flag to 1 for ${year} ${quarter}`); + } catch (error) { + console.error(`[${new Date().toISOString()}] Error updating ipi_calculated flag:`, error); + throw error; + } finally { + connection.release(); + } + } + /** * Main scheduler logic - runs daily */ @@ -197,6 +220,9 @@ class AutomatedSchedulerService { latestWindow.quarter ); + // Step 5: Update ipi_calculated flag to 1 + await this.updateIPICalculatedFlag(latestWindow.year, latestWindow.quarter); + console.log(`[${new Date().toISOString()}] ========================================`); console.log(`[${new Date().toISOString()}] All scheduled tasks completed successfully`); console.log(`[${new Date().toISOString()}] Survey Result:`, JSON.stringify(surveyResult, null, 2));