fix: guarantee 7 full period slots per day for all working days (Monday-Friday) with free period padding
This commit is contained in:
@@ -803,11 +803,32 @@ export async function fetchImsTimetable(_token: string, regNumber: string, _forc
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate weeklySchedule from periodMap (INCLUDE ALL VALID PERIODS & DAYS)
|
// Populate weeklySchedule from periodMap (Ensure EVERY day Monday-Friday has EXACTLY 7 periods)
|
||||||
Object.keys(periodMap).forEach(dayKey => {
|
const standardDays: (keyof WeeklySchedule)[] = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'];
|
||||||
const day = dayKey as keyof WeeklySchedule;
|
|
||||||
const dayPeriods = Object.values(periodMap[day]).sort((a, b) => a.periodNumber - b.periodNumber);
|
standardDays.forEach((day) => {
|
||||||
weeklySchedule[day] = dayPeriods;
|
const existingMap = periodMap[day] || {};
|
||||||
|
const fullDayPeriods: TimetablePeriod[] = [];
|
||||||
|
|
||||||
|
for (let pNum = 1; pNum <= 7; pNum++) {
|
||||||
|
const periodIndex = pNum - 1;
|
||||||
|
if (existingMap[pNum]) {
|
||||||
|
fullDayPeriods.push(existingMap[pNum]);
|
||||||
|
} else {
|
||||||
|
fullDayPeriods.push({
|
||||||
|
periodNumber: pNum,
|
||||||
|
timeSlot: timeSlots[periodIndex] || `Period ${pNum}`,
|
||||||
|
startTime: startTimes[periodIndex] || '',
|
||||||
|
endTime: endTimes[periodIndex] || '',
|
||||||
|
subjectCode: 'FREE',
|
||||||
|
subjectName: 'Free Period / Library',
|
||||||
|
staffName: 'Self Study',
|
||||||
|
type: 'THEORY',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
weeklySchedule[day] = fullDayPeriods;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user