74ba55c20b
* upgrade gulp-babel * upgrade babel-eslint * upgrade eslint-friendly-formatter * start upgrading chai * start to upgrade eslint * restore skipped tests * start to upgrqde monk * fix linting and remove unused file * fix mocha notifications, and common tests * fix unit tests * start to fix initrgration tests * more integration tests fixes * upgrade monk to latest version * lint /scripts * migrations: start moving to /archive unused migrations and run eslint with --fix * lint migrations * fix more integration tests * fix test
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/* let migrationName = 'Jackalopes for Unlimited Subscribers'; */
|
|
|
|
/*
|
|
* This migration will find users with unlimited subscriptions who are also eligible for Jackalope mounts, and award them
|
|
*/
|
|
import Bluebird from 'bluebird';
|
|
|
|
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({
|
|
'purchased.plan.customerId': 'habitrpg',
|
|
}).cursor();
|
|
|
|
cursor.on('data', async (user) => {
|
|
console.log(`User: ${ user._id}`);
|
|
|
|
let groupList = [];
|
|
if (user.party._id) groupList.push(user.party._id);
|
|
groupList = groupList.concat(user.guilds);
|
|
|
|
let subscribedGroup =
|
|
await Group.findOne({
|
|
_id: {$in: groupList},
|
|
'purchased.plan.planId': 'group_monthly',
|
|
'purchased.plan.dateTerminated': null,
|
|
},
|
|
{_id: 1}
|
|
);
|
|
|
|
if (subscribedGroup) {
|
|
User.update({_id: user._id}, {$set: {'items.mounts.Jackalope-RoyalPurple': true}}).exec();
|
|
promises.push(user.save());
|
|
}
|
|
});
|
|
|
|
cursor.on('close', async () => {
|
|
console.log('done');
|
|
return await Bluebird.all(promises);
|
|
});
|
|
}
|
|
|
|
module.exports = handOutJackalopes;
|