Added end date option to group plan migration (#8588)

This commit is contained in:
Keith Holliday
2017-03-23 10:40:15 -06:00
committed by GitHub
parent 77ff91868e
commit 624566ecec
2 changed files with 33 additions and 27 deletions

View File

@@ -5,11 +5,12 @@ var authorUuid = ''; //... own data is done
/* /*
* This migrations will add a free subscription to a specified group * This migrations will add a free subscription to a specified group
*/ */
import moment from 'moment';
import { model as Group } from '../../website/server/models/group'; import { model as Group } from '../../website/server/models/group';
// @TODO: this should probably be a GroupManager library method // @TODO: this should probably be a GroupManager library method
async function addUnlimitedSubscription (groupId) { async function addUnlimitedSubscription (groupId, dateTerminated) {
let group = await Group.findById(groupId); let group = await Group.findById(groupId);
group.purchased.plan.customerId = "group-unlimited"; group.purchased.plan.customerId = "group-unlimited";
@@ -18,6 +19,10 @@ async function addUnlimitedSubscription (groupId) {
group.purchased.plan.paymentMethod = "Group Unlimited"; group.purchased.plan.paymentMethod = "Group Unlimited";
group.purchased.plan.planId = "group_monthly"; group.purchased.plan.planId = "group_monthly";
group.purchased.plan.dateTerminated = null; 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.owner = ObjectId();
group.purchased.plan.subscriptionId = ""; group.purchased.plan.subscriptionId = "";
@@ -29,5 +34,7 @@ module.exports = async function addUnlimitedSubscriptionCreator () {
if (!groupId) throw Error('Group ID is required'); if (!groupId) throw Error('Group ID is required');
let result = await addUnlimitedSubscription(groupId) let dateTerminated = process.argv[3];
let result = await addUnlimitedSubscription(groupId, dateTerminated);
}; };

View File

@@ -1,25 +1,24 @@
require("babel-register"); require("babel-register");
require("babel-polyfill"); require("babel-polyfill");
// This file must use ES5, everything required can be in ES6 // This file must use ES5, everything required can be in ES6
function setUpServer () { function setUpServer () {
var nconf = require('nconf'); var nconf = require('nconf');
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var Bluebird = require('bluebird'); var Bluebird = require('bluebird');
var setupNconf = require('../website/server/libs/setupNconf'); var setupNconf = require('../website/server/libs/setupNconf');
setupNconf(); setupNconf();
// We require src/server and npt src/index because // We require src/server and npt src/index because
// 1. nconf is already setup // 1. nconf is already setup
// 2. we don't need clustering // 2. we don't need clustering
require('../website/server/server'); // eslint-disable-line global-require require('../website/server/server'); // eslint-disable-line global-require
} }
setUpServer(); setUpServer();
// Replace this with your migration // Replace this with your migration
var processUsers = require('./groups/update-groups-with-group-plans'); var processUsers = require('./groups/update-groups-with-group-plans');
processUsers() processUsers()
.catch(function (err) { .catch(function (err) {
console.log(err) console.log(err)
}) })