Skip to content

Commit 5806945

Browse files
author
ICook094
committed
Update email job to send A3 every 3 days instead of 5
1 parent e1763a1 commit 5806945

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

server/jobs/reminderEmail.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
11
const emailService = require("../services/emailService");
2-
// const Submission = require("../models/InternshipRequest"); // ❌ Remove this
32
const NotificationLog = require("../models/NotifLog");
43
const User = require("../models/User");
54
const UserTokenRequest = require("../models/TokenRequest");
65
const logger = require("../utils/logger");
76
const dayjs = require("dayjs");
87

98
// ================= Coordinator Reminder =================
9+
// Sends reminders for
10+
// A1 (InternshipRequest) every 5 working days
11+
// A2 (Weekly Reports) every 5 working days
12+
// A3 (Evaluations) every 3 days
1013
const coordinatorReminder = async () => {
1114
const now = dayjs();
1215
const fiveWorkingDays = now.subtract(7, "day").toDate();
16+
const threeDays = now.subtract(3, 'day').toDate();
1317

1418
try {
1519
const pendingSubs = await getAllForms({
1620
coordinator_status: "pending",
1721
supervisor_status: "approved",
1822
createdAt: { $lt: fiveWorkingDays },
23+
evaluations: { $size: 0 },
1924
});
2025

21-
for (const submission of pendingSubs) {
26+
const pendingEvals = await getAllForms({
27+
coordinator_status: "pending",
28+
supervisor_status: "approved",
29+
createdAt: { $lt: threeDays },
30+
evaluations: { $ne: [] },
31+
});
32+
33+
await sendCoordinatorReminder(pendingSubs, 5, now);
34+
await sendCoordinatorReminder(pendingEvals, 3, now);
35+
} catch (err) {
36+
logger.error("❌ Error in coordinatorReminder:", err.message);
37+
}
38+
};
39+
40+
const sendCoordinatorReminder = async (subs, nextDueIn, now) => {
41+
try {
42+
for (const submission of subs) {
2243
const student = await User.findById(submission.student_id);
2344
const coordinator = await User.findById(submission.coordinator_id);
2445

2546
const reminderCount = submission.coordinator_reminder_count || 0;
2647
const lastReminded = submission.last_coordinator_reminder_at || submission.createdAt;
27-
const nextReminderDue = dayjs(lastReminded).add(5, "day");
48+
const nextReminderDue = dayjs(lastReminded).add(nextDueIn, "day");
2849
const shouldRemindAgain = now.isAfter(nextReminderDue);
2950

3051
if (reminderCount >= 2 && shouldRemindAgain && !submission.studentNotified) {
3152
await emailService.sendEmail({
3253
to: student.email,
3354
subject: `Coordinator Not Responding for "${submission.name}"`,
3455
html: `<p>Your submission "${submission.name}" has not been approved by the coordinator even after 2 reminders.</p>
35-
<p>You can now choose to <strong>resend</strong> or <strong>delete</strong> the request.</p>`,
56+
<p>You can now choose to <strong>resend</strong> or <strong>delete</strong> the request.</p>`,
3657
text: `Your submission "${submission.name}" is still awaiting coordinator approval.`,
3758
});
3859

@@ -63,7 +84,7 @@ const coordinatorReminder = async () => {
6384
}
6485
}
6586
} catch (err) {
66-
logger.error("❌ Error in coordinatorReminder:", err.message);
87+
logger.error("❌ Error in sendCoordinatorReminder:", err.message);
6788
}
6889
};
6990

0 commit comments

Comments
 (0)