Files
habitica/migrations/groups/update-groups-with-group-plans.js
Matteo Pagliazzi cb42a31c43 Node 8 (WIP) (#9946)
* start upgrade to node 8

* upgrade travis

* improve travis

* Remove bluebird, babel (except for modules) from server (WIP) (#9947)

* remove bluebird, babel from server (except for modules)

* fixes

* fix path

* fix path

* fix export

* fix export

* fix test

* fix tests

* remove plugin for transform-object-rest-spread since it is supported in node8

* babel: correct syntax rest spread

* remove bluebird

* update migrations archive readme

* fix package-lock.json

* fix typo

* add package-loc
2018-03-15 19:59:36 +01:00

34 lines
931 B
JavaScript

/*
let migrationName = 'ResyncGroupPlanMembers';
let authorName = 'TheHollidayInn'; // in case script author needs to know when their ...
let authorUuid = ''; // ... own data is done
*/
/*
* 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 = [];
cursor.on('data', (group) => {
promises.push(payments.addSubscriptionToGroupUsers(group));
promises.push(group.save());
});
cursor.on('close', async () => {
return await Promise.all(promises);
});
}
module.exports = updateGroupsWithGroupPlans;