-
Notifications
You must be signed in to change notification settings - Fork 0
/
poll.js
28 lines (27 loc) · 876 Bytes
/
poll.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
const updateHistory = require('./functions/updateHistory');
const User = require('./models/User');
module.exports = async () => {
try {
const users = await User.find({
doNotTrack: false,
inactiveAt: { $gte: Date.now() }
});
if (users.length > 0) {
const result = await Promise.allSettled(
users.map(userE => updateHistory(null, userE.spID))
);
const toStream = result
.filter(resultE => resultE.status === 'fulfilled')
.map(resultE => resultE.value);
const report = `Update conducted at ${new Date()} yielded ${
result.filter(resultE => resultE.status === 'rejected').length > 0
? result.filter(resultE => resultE.status === 'rejected').length
: 'no'
} errors`;
console.log(report);
return toStream;
}
} catch (err) {
console.error(err);
}
};