diff --git a/migrations/groups/add-unlimited-subscription.js b/migrations/groups/add-unlimited-subscription.js index 653024d0b8..4a7eb27a02 100644 --- a/migrations/groups/add-unlimited-subscription.js +++ b/migrations/groups/add-unlimited-subscription.js @@ -5,11 +5,12 @@ var authorUuid = ''; //... own data is done /* * This migrations will add a free subscription to a specified group */ +import moment from 'moment'; import { model as Group } from '../../website/server/models/group'; // @TODO: this should probably be a GroupManager library method -async function addUnlimitedSubscription (groupId) { +async function addUnlimitedSubscription (groupId, dateTerminated) { let group = await Group.findById(groupId); group.purchased.plan.customerId = "group-unlimited"; @@ -18,6 +19,10 @@ async function addUnlimitedSubscription (groupId) { group.purchased.plan.paymentMethod = "Group Unlimited"; group.purchased.plan.planId = "group_monthly"; group.purchased.plan.dateTerminated = null; + if (dateTerminated) { + let dateToEnd = moment(dateTerminated).toDate(); + group.purchased.plan.dateTerminated = dateToEnd; + } // group.purchased.plan.owner = ObjectId(); group.purchased.plan.subscriptionId = ""; @@ -29,5 +34,7 @@ module.exports = async function addUnlimitedSubscriptionCreator () { if (!groupId) throw Error('Group ID is required'); - let result = await addUnlimitedSubscription(groupId) + let dateTerminated = process.argv[3]; + + let result = await addUnlimitedSubscription(groupId, dateTerminated); }; diff --git a/migrations/migration-runner.js b/migrations/migration-runner.js index f767f60105..4f04540268 100644 --- a/migrations/migration-runner.js +++ b/migrations/migration-runner.js @@ -1,25 +1,24 @@ -require("babel-register"); -require("babel-polyfill"); - -// This file must use ES5, everything required can be in ES6 - -function setUpServer () { - var nconf = require('nconf'); - var mongoose = require('mongoose'); - var Bluebird = require('bluebird'); - var setupNconf = require('../website/server/libs/setupNconf'); - setupNconf(); - // We require src/server and npt src/index because - // 1. nconf is already setup - // 2. we don't need clustering - require('../website/server/server'); // eslint-disable-line global-require -} -setUpServer(); - -// Replace this with your migration -var processUsers = require('./groups/update-groups-with-group-plans'); -processUsers() - .catch(function (err) { - console.log(err) - }) - +require("babel-register"); +require("babel-polyfill"); + +// This file must use ES5, everything required can be in ES6 + +function setUpServer () { + var nconf = require('nconf'); + var mongoose = require('mongoose'); + var Bluebird = require('bluebird'); + var setupNconf = require('../website/server/libs/setupNconf'); + setupNconf(); + // We require src/server and npt src/index because + // 1. nconf is already setup + // 2. we don't need clustering + require('../website/server/server'); // eslint-disable-line global-require +} +setUpServer(); + +// Replace this with your migration +var processUsers = require('./groups/update-groups-with-group-plans'); +processUsers() + .catch(function (err) { + console.log(err) + }) \ No newline at end of file