Files
habitica/migrations/groups/habitrpg-jackalopes.js
Phillip Thelen f8d315ff6e Upgrade to mongoose 7 (#14971)
* remove some unused dependencies

* update mongoose version

* make common tests pass

* Make unit tests pass

* make api v3 integration tests pass

* fix lint issues

* fix issue with package-lock

* fix(lint): we don't need no .js

* fix(lint): update to latest config-habitrpg

* chore(npm): update package locks

* fix(test): replace deprecated fn

* chore(package): update eslint-habitrpg again

* fix(lint): server linting

* fix(lint): client linting

* fix(client): correct mangled common imports

* chore(npm): update package-locks

* fix(lint): punctuation, module

---------

Co-authored-by: SabreCat <sabrecat@gmail.com>
Co-authored-by: SabreCat <sabe@habitica.com>
2024-01-16 15:18:47 -06:00

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 { model as Group } from '../../website/server/models/group';
import { model as User } from '../../website/server/models/user';
async function handOutJackalopes () {
const promises = [];
const 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);
const 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 Promise.all(promises);
});
}
export default handOutJackalopes;