diff --git a/app/controllers/dashboard.controller.js b/app/controllers/dashboard.controller.js index b41e8ad..f7e8a14 100644 --- a/app/controllers/dashboard.controller.js +++ b/app/controllers/dashboard.controller.js @@ -68,9 +68,6 @@ exports.getEstablishmentDashboard = async (req, res) => { const quarters = getPrevCurrNextQuarter(today); - - - const submission_history = await Submission.findAll({ where: { establishment_id }, order: [["created_at", "DESC"]], @@ -131,6 +128,40 @@ exports.getEstablishmentDashboard = async (req, res) => { }; } + + let surveyReady = []; + + const activeQuarters = await QuarterlyWindowsConfiguration.findAll({ + where: { is_active: true }, + order: [["created_at", "DESC"]], + }); + + if (activeQuarters?.length > 0) { + + for (const q of activeQuarters) { + + const submissionMatch = await Submission.findOne({ + where: { + year: q.year, + quarter: q.quarter, + establishment_id: establishment_id + } + }); + + // if not submitted yet → add for start survey + if (!submissionMatch) { + surveyReady.push({ + quarterId: q.id, + quarter: q.quarter, + start_date: q.start_date, + end_date: q.end_date, + year: q.year, + }); + } + } + } + + res.status(200).json({ status: "success", data: { @@ -138,6 +169,7 @@ exports.getEstablishmentDashboard = async (req, res) => { submission_status: submissionStatus, next_deadline: nextDeadline, last_submission: lastSubmissionInfo, + survey_ready: surveyReady, submission_history, }, });