2018-02-17 17:11:24 +00:00
|
|
|
/*
|
|
|
|
|
let migrationName = 'ResyncGroupPlanMembers';
|
|
|
|
|
let authorName = 'TheHollidayInn'; // in case script author needs to know when their ...
|
|
|
|
|
let authorUuid = ''; // ... own data is done
|
|
|
|
|
*/
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
/*
|
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
|
2017-03-11 00:18:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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';
|
2017-03-11 00:18:02 +00:00
|
|
|
|
|
|
|
|
async function updateGroupsWithGroupPlans () {
|
2019-10-08 14:57:10 +00:00
|
|
|
const cursor = Group.find({
|
2017-03-11 00:18:02 +00:00
|
|
|
'purchased.plan.planId': 'group_monthly',
|
|
|
|
|
'purchased.plan.dateTerminated': null,
|
|
|
|
|
}).cursor();
|
|
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
const promises = [];
|
2017-03-11 00:18:02 +00:00
|
|
|
|
2019-10-08 14:57:10 +00:00
|
|
|
cursor.on('data', group => {
|
2017-03-11 00:18:02 +00:00
|
|
|
promises.push(payments.addSubscriptionToGroupUsers(group));
|
2018-02-17 17:11:24 +00:00
|
|
|
promises.push(group.save());
|
2017-03-11 00:18:02 +00:00
|
|
|
});
|
|
|
|
|
|
2019-10-08 16:36:55 +00:00
|
|
|
cursor.on('close', async () => Promise.all(promises));
|
2018-02-17 17:11:24 +00:00
|
|
|
}
|
2017-03-11 00:18:02 +00:00
|
|
|
|
2019-10-15 13:32:53 +00:00
|
|
|
export default updateGroupsWithGroupPlans;
|