wfh_2020_notifications.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const NotificationsHandler = require('../../app/src/Features/Notifications/NotificationsHandler')
  2. const { db } = require('../../app/src/infrastructure/mongojs')
  3. const async = require('async')
  4. const templateKey = 'wfh_2020_upgrade_offer'
  5. const key = 'wfh-2020-upgrade-2020-06-01'
  6. db.subscriptions.aggregate(
  7. { $match: { teamName: /(Work From Home|Work from Home)/ } },
  8. { $unwind: '$member_ids' },
  9. { $group: { _id: null, memberIds: { $addToSet: '$member_ids' } } },
  10. function(err, results) {
  11. if (err) {
  12. throw err
  13. }
  14. const userIds = results[0].memberIds
  15. async.eachLimit(
  16. userIds,
  17. 10,
  18. function(userId, callback) {
  19. NotificationsHandler.createNotification(
  20. userId,
  21. key,
  22. templateKey,
  23. {},
  24. null,
  25. true,
  26. function(err) {
  27. if (err) {
  28. return callback(err)
  29. }
  30. console.log('Notification created for user ' + userId)
  31. callback()
  32. }
  33. )
  34. },
  35. function() {
  36. console.log('Done')
  37. process.exit(0)
  38. }
  39. )
  40. }
  41. )