2018-02-17 17:11:24 +00:00
|
|
|
/* let migrationName = 'Jackalopes for Unlimited Subscribers'; */
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This migration will find users with unlimited subscriptions who are also eligible for Jackalope mounts, and award them
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { model as Group } from '../../website/server/models/group';
|
|
|
|
|
import { model as User } from '../../website/server/models/user';
|
|
|
|
|
|
|
|
|
|
async function handOutJackalopes () {
|
|
|
|
|
let promises = [];
|
|
|
|
|
let cursor = User.find({
|
2018-02-17 17:11:24 +00:00
|
|
|
'purchased.plan.customerId': 'habitrpg',
|
2017-03-11 00:18:02 +00:00
|
|
|
}).cursor();
|
|
|
|
|
|
2018-02-17 17:11:24 +00:00
|
|
|
cursor.on('data', async (user) => {
|
|
|
|
|
console.log(`User: ${ user._id}`);
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
let groupList = [];
|
|
|
|
|
if (user.party._id) groupList.push(user.party._id);
|
|
|
|
|
groupList = groupList.concat(user.guilds);
|
|
|
|
|
|
|
|
|
|
let subscribedGroup =
|
|
|
|
|
await Group.findOne({
|
2018-02-17 17:11:24 +00:00
|
|
|
_id: {$in: groupList},
|
2017-03-11 00:18:02 +00:00
|
|
|
'purchased.plan.planId': 'group_monthly',
|
|
|
|
|
'purchased.plan.dateTerminated': null,
|
|
|
|
|
},
|
2018-02-17 17:11:24 +00:00
|
|
|
{_id: 1}
|
|
|
|
|
);
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
if (subscribedGroup) {
|
2018-02-17 17:11:24 +00:00
|
|
|
User.update({_id: user._id}, {$set: {'items.mounts.Jackalope-RoyalPurple': true}}).exec();
|
2017-03-11 00:18:02 +00:00
|
|
|
promises.push(user.save());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-02-17 17:11:24 +00:00
|
|
|
cursor.on('close', async () => {
|
2017-03-11 00:18:02 +00:00
|
|
|
console.log('done');
|
2018-03-15 18:59:36 +00:00
|
|
|
return await Promise.all(promises);
|
2017-03-11 00:18:02 +00:00
|
|
|
});
|
2018-02-17 17:11:24 +00:00
|
|
|
}
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
module.exports = handOutJackalopes;
|