feat: add soft delete for classes with cascade to sessions and linked records
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user