2020-07-24 07:46:25 -04:00
|
|
|
const mongojs = require('../../app/src/infrastructure/mongojs')
|
|
|
|
const { db } = mongojs
|
|
|
|
const async = require('async')
|
|
|
|
|
2020-07-27 09:57:54 -04:00
|
|
|
db.deletedSubscriptions.aggregate(
|
|
|
|
{ $match: { 'subscription.teamName': /(Work From Home|Work from Home)/ } },
|
|
|
|
{ $unwind: '$subscription.member_ids' },
|
|
|
|
{
|
|
|
|
$group: { _id: null, memberIds: { $addToSet: '$subscription.member_ids' } }
|
|
|
|
},
|
2020-07-24 07:46:25 -04:00
|
|
|
function(err, results) {
|
2020-07-24 11:07:11 -04:00
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!results.length) {
|
|
|
|
console.error('No users found')
|
|
|
|
process.exit(1)
|
2020-07-24 07:46:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const userIds = results[0].memberIds
|
|
|
|
|
|
|
|
console.log('Id,First Name,Last Name,Sign Up Date,Emails')
|
|
|
|
|
|
|
|
async.eachLimit(
|
|
|
|
userIds,
|
|
|
|
10,
|
|
|
|
function(userId, callback) {
|
|
|
|
db.users.findOne(userId, function(err, user) {
|
2020-07-28 05:37:24 -04:00
|
|
|
if (user) {
|
|
|
|
const emails = user.emails.map(email => email.email)
|
|
|
|
console.log(
|
|
|
|
`${user._id},${user.first_name || ''},${user.last_name || ''},${
|
|
|
|
user.signUpDate
|
|
|
|
},${emails.join(',')}`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
console.error('A group user was not found')
|
|
|
|
}
|
2020-07-24 07:46:25 -04:00
|
|
|
callback(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
if (err) {
|
2020-07-24 11:07:11 -04:00
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
2020-07-24 07:46:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|