test
This commit is contained in:
parent
53eb76f6b3
commit
0640d64e5d
@ -808,58 +808,50 @@ 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 query = `
|
const config = await QuarterlyWindowConfig.findOne({
|
||||||
SELECT id, survey_name, year, quarter, start_date, end_date,
|
where: {
|
||||||
grace_periods_days, is_active, created_at, created_by,
|
year: current_year,
|
||||||
updated_at, updated_by, assigned, responded
|
quarter: current_quarter
|
||||||
FROM quarterly_windows_configuration_master
|
}
|
||||||
WHERE year = ? AND quarter = ?
|
});
|
||||||
LIMIT 1
|
|
||||||
`;
|
|
||||||
|
|
||||||
const [quarterConfigs] = await db.query(query, [current_year, current_quarter]);
|
if (!config) {
|
||||||
|
|
||||||
// Check if quarter configuration exists
|
|
||||||
if (!quarterConfigs || quarterConfigs.length === 0) {
|
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
message: `No configuration found for Quarter ${current_quarter} ${current_year}`
|
message: `No configuration found for Quarter ${current_quarter} ${current_year}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = quarterConfigs[0];
|
|
||||||
|
|
||||||
// Check if quarter is active
|
|
||||||
if (config.is_active === 0) {
|
if (config.is_active === 0) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
status: "failed",
|
status: "failed",
|
||||||
message: `Quarter ${current_quarter} ${current_year} is not active. Cannot create surveys.`
|
message: `Quarter ${current_quarter} ${current_year} is not active`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the final deadline (end_date + grace_periods_days)
|
|
||||||
const endDate = new Date(config.end_date);
|
const endDate = new Date(config.end_date);
|
||||||
const gracePeriodDays = config.grace_periods_days || 0;
|
const graceDays = Number(config.grace_periods_days || 0);
|
||||||
|
|
||||||
const finalDeadline = new Date(endDate);
|
const finalDeadline = new Date(endDate);
|
||||||
finalDeadline.setDate(finalDeadline.getDate() + gracePeriodDays);
|
finalDeadline.setDate(finalDeadline.getDate() + graceDays);
|
||||||
|
|
||||||
const currentDateTime = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
// Check if the quarter is closed
|
if (now > finalDeadline) {
|
||||||
if (currentDateTime > finalDeadline) {
|
|
||||||
const formattedDeadline = finalDeadline.toISOString().split('T')[0];
|
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
status: "failed",
|
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,
|
quarter_closed: true,
|
||||||
|
message: `Quarter ${current_quarter} ${current_year} is closed`,
|
||||||
deadline: finalDeadline.toISOString(),
|
deadline: finalDeadline.toISOString(),
|
||||||
current_time: currentDateTime.toISOString()
|
current_time: now.toISOString()
|
||||||
});
|
});
|
||||||
}else{
|
}
|
||||||
|
|
||||||
|
|
||||||
const quarter_periods = getQuarterPeriods(Number(current_year), current_quarter);
|
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