From 856f221399138591b979ea86ab049a40a1ad13fa Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Dec 2025 11:56:39 +0530 Subject: [PATCH] Closed Quarter restricted --- app/controllers/dashboard.controller.js | 10 ++++++++ app/controllers/submission.controller.js | 31 +++--------------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/app/controllers/dashboard.controller.js b/app/controllers/dashboard.controller.js index e144b88..d92a124 100644 --- a/app/controllers/dashboard.controller.js +++ b/app/controllers/dashboard.controller.js @@ -143,6 +143,16 @@ exports.getEstablishmentDashboard = async (req, res) => { if (activeQuarters?.length > 0) { for (const q of activeQuarters) { + const endDate = new Date(q.end_date); + const graceDays = Number(q.grace_periods_days || 0); + const finalDeadline = new Date(endDate); + finalDeadline.setDate(finalDeadline.getDate() + graceDays); + const now = new Date(); + + // Skip this quarter if it's closed (deadline has passed) + if (now > finalDeadline) { + continue; + } const submissionMatch = await Submission.findOne({ where: { diff --git a/app/controllers/submission.controller.js b/app/controllers/submission.controller.js index 8102b7e..11f3020 100644 --- a/app/controllers/submission.controller.js +++ b/app/controllers/submission.controller.js @@ -811,7 +811,8 @@ exports.getQuarterPeriods = async (req, res) => { const config = await QuarterlyWindowsConfiguration.findOne({ where: { year: current_year, - quarter: current_quarter + quarter: current_quarter, + is_active: true } }); @@ -820,33 +821,7 @@ exports.getQuarterPeriods = async (req, res) => { status: "failed", message: `No configuration found for Quarter ${current_quarter} ${current_year}` }); - } - - if (config.is_active === 0) { - return res.status(403).json({ - status: "failed", - message: `Quarter ${current_quarter} ${current_year} is not active` - }); - } - - - const endDate = new Date(config.end_date); - const graceDays = Number(config.grace_periods_days || 0); - - const finalDeadline = new Date(endDate); - finalDeadline.setDate(finalDeadline.getDate() + graceDays); - - const now = new Date(); - - if (now > finalDeadline) { - return res.status(403).json({ - status: "failed", - quarter_closed: true, - message: `Quarter ${current_quarter} ${current_year} is closed. The grace period ended on ${finalDeadline}. Cannot create surveys for this quarter.`, - deadline: finalDeadline.toISOString(), - current_time: now.toISOString() - }); - } + } const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter); return res.status(200).json({ status: "success", data: quarter_periods });