feat: add soft delete for classes with cascade to sessions and linked records

This commit is contained in:
2026-08-21 13:19:50 +03:30
parent 5b56171328
commit e34fd25af7
15 changed files with 184 additions and 33 deletions
+4 -2
View File
@@ -38,8 +38,9 @@ const runClassReminderJob = async () => {
status: 'scheduled',
reminderSentAt: null,
day: { $gte: dayFrom, $lte: dayTo },
isDeleted: { $ne: true }
})
.populate({ path: 'class', select: 'name students startDate days startTime endTime uniqueCode' })
.populate({ path: 'class', select: 'name students startDate days startTime endTime uniqueCode isDeleted' })
.populate({ path: 'course', select: 'title' })
.lean();
@@ -48,6 +49,7 @@ const runClassReminderJob = async () => {
if (!startAt || startAt < windowStart || startAt > windowEnd) continue;
const classDoc = session.class;
if (!classDoc || classDoc.isDeleted) continue;
const studentIds = classDoc?.students || [];
if (studentIds.length === 0) {
await Session.updateOne({ _id: session._id }, { reminderSentAt: new Date() });
@@ -58,7 +60,7 @@ const runClassReminderJob = async () => {
const timeLabel = session.startTime;
const placeLabel = session.place || '-';
const classSessions = classDoc?._id
? await Session.find({ class: classDoc._id }).select('day startTime endTime').sort({ day: 1 }).lean()
? await Session.find({ class: classDoc._id, isDeleted: { $ne: true } }).select('day startTime endTime').sort({ day: 1 }).lean()
: [];
const schedule = buildClassScheduleContext(classDoc, classSessions, session);