-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.js
30 lines (27 loc) · 940 Bytes
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const Complaint = require('./models/complaints');
const emailServer = require('./utils/sendEmail');
const hour = 60 * 60 * 1000;
const updateComplaints = async () => {
const complaints = await Complaint.find({
status: { $in: ['Open', 'Pending', 'Re-Open'] },
// reviewStartedAt: { $gte: [new Date(Date.now()) - hour,hour] }
}).populate('assignedTo');
complaints.map((complaint) => {
if (complaint.assignedTo) {
emailServer.sendNotificationEmail(complaint);
}
});
};
const timer = setInterval(updateComplaints, hour);
const mins = 15 * 60 * 1000;
const archiveComplaints = async () => {
const complaints = await Complaint.find({
archivingTime: { $lte: Date.now() },
archived: false,
});
complaints.map((complaint) => {
complaint.archived = true;
complaint.save();
});
};
const archiveTimer = setInterval(archiveComplaints, mins);