test
This commit is contained in:
parent
e18346a474
commit
d7d91fac77
@ -808,9 +808,58 @@ exports.getQuarterPeriods = async (req, res) => {
|
|||||||
.json({ status: "failed", message: "current_year and current_quarter are required" });
|
.json({ status: "failed", message: "current_year and current_quarter are required" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter);
|
const query = `
|
||||||
|
SELECT id, survey_name, year, quarter, start_date, end_date,
|
||||||
|
grace_periods_days, is_active, created_at, created_by,
|
||||||
|
updated_at, updated_by, assigned, responded
|
||||||
|
FROM quarterly_windows_configuration_master
|
||||||
|
WHERE year = ? AND quarter = ?
|
||||||
|
LIMIT 1
|
||||||
|
`;
|
||||||
|
|
||||||
|
const [quarterConfigs] = await db.query(query, [current_year, current_quarter]);
|
||||||
|
|
||||||
|
// Check if quarter configuration exists
|
||||||
|
if (!quarterConfigs || quarterConfigs.length === 0) {
|
||||||
|
return res.status(404).json({
|
||||||
|
status: "failed",
|
||||||
|
message: `No configuration found for Quarter ${current_quarter} ${current_year}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = quarterConfigs[0];
|
||||||
|
|
||||||
|
// Check if quarter is active
|
||||||
|
if (config.is_active === 0) {
|
||||||
|
return res.status(403).json({
|
||||||
|
status: "failed",
|
||||||
|
message: `Quarter ${current_quarter} ${current_year} is not active. Cannot create surveys.`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the final deadline (end_date + grace_periods_days)
|
||||||
|
const endDate = new Date(config.end_date);
|
||||||
|
const gracePeriodDays = config.grace_periods_days || 0;
|
||||||
|
const finalDeadline = new Date(endDate);
|
||||||
|
finalDeadline.setDate(finalDeadline.getDate() + gracePeriodDays);
|
||||||
|
|
||||||
|
const currentDateTime = new Date();
|
||||||
|
|
||||||
|
// Check if the quarter is closed
|
||||||
|
if (currentDateTime > finalDeadline) {
|
||||||
|
const formattedDeadline = finalDeadline.toISOString().split('T')[0];
|
||||||
|
return res.status(403).json({
|
||||||
|
status: "failed",
|
||||||
|
message: `Quarter ${current_quarter} ${current_year} is closed. The grace period ended on ${formattedDeadline}. Cannot create surveys for this quarter.`,
|
||||||
|
quarter_closed: true,
|
||||||
|
deadline: finalDeadline.toISOString(),
|
||||||
|
current_time: currentDateTime.toISOString()
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
|
||||||
|
const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter);
|
||||||
return res.status(200).json({ status: "success", data: quarter_periods });
|
return res.status(200).json({ status: "success", data: quarter_periods });
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err.message);
|
logger.error(err.message);
|
||||||
logger.error(`Stack trace: ${err.stack}`);
|
logger.error(`Stack trace: ${err.stack}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user