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
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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';
|
|
|
|
|
import * as payments from '../../website/server/libs/payments';
|
|
|
|
|
|
|
|
|
|
async function updateGroupsWithGroupPlans () {
|
|
|
|
|
let cursor = Group.find({
|
|
|
|
|
'purchased.plan.planId': 'group_monthly',
|
|
|
|
|
'purchased.plan.dateTerminated': null,
|
|
|
|
|
}).cursor();
|
|
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
|
|
2018-02-17 17:11:24 +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
|
|
|
});
|
|
|
|
|
|
2018-02-17 17:11:24 +00:00
|
|
|
cursor.on('close', async () => {
|
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 = updateGroupsWithGroupPlans;
|