habitica/migrations/groups/update-groups-with-group-plans.js

32 lines
913 B
JavaScript
Raw Normal View History

/*
let migrationName = 'ResyncGroupPlanMembers';
let authorName = 'TheHollidayInn'; // in case script author needs to know when their ...
let authorUuid = ''; // ... own data is done
*/
/*
2019-10-08 16:36:55 +00:00
* This migrations will iterate through all groups with a group plan
* a subscription and resync the free subscription to all members
*/
import { model as Group } from '../../website/server/models/group';
2019-10-08 16:36:55 +00:00
import payments from '../../website/server/libs/payments/payments';
async function updateGroupsWithGroupPlans () {
2019-10-08 14:57:10 +00:00
const cursor = Group.find({
'purchased.plan.planId': 'group_monthly',
'purchased.plan.dateTerminated': null,
}).cursor();
2019-10-08 14:57:10 +00:00
const promises = [];
2019-10-08 14:57:10 +00:00
cursor.on('data', group => {
promises.push(payments.addSubscriptionToGroupUsers(group));
promises.push(group.save());
});
2019-10-08 16:36:55 +00:00
cursor.on('close', async () => Promise.all(promises));
}
module.exports = updateGroupsWithGroupPlans;