mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
018a44eeb5
[misc] normalize mongo imports GitOrigin-RevId: ac653d9982e0d36736b90f4c03d4c00be88ea76a
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
const NotificationsHandler = require('../../app/src/Features/Notifications/NotificationsHandler')
|
|
|
|
const { db } = require('../../app/src/infrastructure/mongojs')
|
|
const async = require('async')
|
|
|
|
const templateKey = 'wfh_2020_upgrade_offer'
|
|
const oldKey = 'wfh-2020-upgrade-2020-06-01'
|
|
const key = 'wfh-2020-upgrade-2020-06-18'
|
|
|
|
db.subscriptions.aggregate(
|
|
{ $match: { teamName: /(Work From Home|Work from Home)/ } },
|
|
{ $unwind: '$member_ids' },
|
|
{ $group: { _id: null, memberIds: { $addToSet: '$member_ids' } } },
|
|
function(err, results) {
|
|
if (err) {
|
|
throw err
|
|
}
|
|
|
|
const userIds = results[0].memberIds
|
|
|
|
async.eachLimit(
|
|
userIds,
|
|
10,
|
|
function(userId, callback) {
|
|
async.series(
|
|
[
|
|
function(cb) {
|
|
db.notifications.findOne(
|
|
{ user_id: userId, key: oldKey },
|
|
function(err, notification) {
|
|
if (err) {
|
|
console.log('Error finding notification for ' + userId)
|
|
cb(err)
|
|
} else if (!notification) {
|
|
cb()
|
|
} else {
|
|
if (notification.templateKey && notification.messageOpts) {
|
|
db.notifications.update(
|
|
{
|
|
_id: notification._id
|
|
},
|
|
{
|
|
$unset: { templateKey: true, messageOpts: true }
|
|
},
|
|
cb
|
|
)
|
|
} else {
|
|
cb()
|
|
}
|
|
}
|
|
}
|
|
)
|
|
},
|
|
function(cb) {
|
|
NotificationsHandler.createNotification(
|
|
userId,
|
|
key,
|
|
templateKey,
|
|
{},
|
|
null,
|
|
true,
|
|
cb
|
|
)
|
|
}
|
|
],
|
|
function(err) {
|
|
if (err) {
|
|
callback(err)
|
|
} else {
|
|
console.log('Notification created for user ' + userId)
|
|
callback()
|
|
}
|
|
}
|
|
)
|
|
},
|
|
function(err) {
|
|
if (err) {
|
|
console.log(err)
|
|
process.exit(1)
|
|
} else {
|
|
console.log('Done')
|
|
process.exit(0)
|
|
}
|
|
}
|
|
)
|
|
}
|
|
)
|