fallback to latest available month when desired month isn't available
parent
5e017abcf1
commit
70657505da
|
|
@ -36,13 +36,31 @@ interface EmployeeSummary {
|
|||
timestamp: string;
|
||||
}
|
||||
|
||||
async function generateMonthlySummary(month: string) {
|
||||
const monthDir = join(REPORTS_DIR, month);
|
||||
if (!existsSync(monthDir)) {
|
||||
console.error(`Month directory not found: ${monthDir}`);
|
||||
async function generateMonthlySummary(requestedMonth: string) {
|
||||
let month = requestedMonth;
|
||||
let monthDir = join(REPORTS_DIR, month);
|
||||
|
||||
if (!existsSync(REPORTS_DIR)) {
|
||||
console.error(`Reports directory not found: ${REPORTS_DIR}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!existsSync(monthDir)) {
|
||||
const availableMonths = readdirSync(REPORTS_DIR)
|
||||
.filter(f => fs.statSync(join(REPORTS_DIR, f)).isDirectory())
|
||||
.filter(f => /^\d{4}$/.test(f))
|
||||
.sort((a, b) => b.localeCompare(a));
|
||||
|
||||
if (availableMonths.length === 0) {
|
||||
console.error(`No month directories found in ${REPORTS_DIR}`);
|
||||
return;
|
||||
}
|
||||
|
||||
month = availableMonths[0];
|
||||
monthDir = join(REPORTS_DIR, month);
|
||||
console.log(`⚠️ Requested month ${requestedMonth} not found. Falling back to latest: ${month}`);
|
||||
}
|
||||
|
||||
console.log(`Processing reports for month: ${month}...`);
|
||||
|
||||
const employees = readdirSync(monthDir).filter(f => fs.statSync(join(monthDir, f)).isDirectory());
|
||||
|
|
|
|||
Loading…
Reference in New Issue