feat: auto generate placeholder nationalId for users and professors, auto calculate class end date

This commit is contained in:
2026-08-21 15:03:18 +03:30
parent cbcf3f55db
commit 30db6582b7
6 changed files with 157 additions and 21 deletions
+27 -1
View File
@@ -109,6 +109,31 @@ const buildClassScheduleContext = (classDoc, sessions = [], currentSession = nul
};
};
const calculateClassEndDate = (startDate, days = [], numberOfSessions = 0) => {
const date = toDate(startDate);
const countNeeded = parseInt(numberOfSessions, 10);
if (!date || isNaN(countNeeded) || countNeeded < 1) return null;
const validDays = normalizeWeekdays(days);
if (!validDays.length) return null;
let current = new Date(date);
let count = 0;
let lastMatchingDate = null;
let safetyLimit = 365 * 5;
while (count < countNeeded && safetyLimit > 0) {
safetyLimit--;
if (validDays.includes(current.getDay())) {
count++;
lastMatchingDate = new Date(current);
}
if (count >= countNeeded) break;
current.setDate(current.getDate() + 1);
}
return lastMatchingDate;
};
module.exports = {
IRAN_WEEK_ORDER,
PERSIAN_WEEKDAYS,
@@ -118,5 +143,6 @@ module.exports = {
formatClassStartDate,
normalizeWeekdays,
normalizeClockTime,
buildClassScheduleContext
buildClassScheduleContext,
calculateClassEndDate
};