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" });
|
||||
}
|
||||
|
||||
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 = await QuarterlyWindowConfig.findOne({
|
||||
where: {
|
||||
year: current_year,
|
||||
quarter: current_quarter
|
||||
}
|
||||
});
|
||||
|
||||
if (!config) {
|
||||
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.`
|
||||
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`,
|
||||
deadline: finalDeadline.toISOString(),
|
||||
current_time: now.toISOString()
|
||||
});
|
||||
}
|
||||
|
||||
// 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 });
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.error(err.message);
|
||||
logger.error(`Stack trace: ${err.stack}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user