This commit is contained in:
Nick Winter 2015-07-09 12:47:04 -07:00
commit fb47efb4f7

View file

@ -14,6 +14,8 @@ User = require '../users/User'
{getSponsoredSubsAmount} = require '../../app/core/utils' {getSponsoredSubsAmount} = require '../../app/core/utils'
recipientCouponID = 'free' recipientCouponID = 'free'
# TODO: rename this to avoid collisions with 'subscriptions' variables
subscriptions = { subscriptions = {
basic: { basic: {
gems: 3500 gems: 3500
@ -71,19 +73,19 @@ class SubscriptionHandler extends Handler
getStripeSubscriptions: (req, res) -> getStripeSubscriptions: (req, res) ->
# console.log 'subscription_handler getStripeSubscriptions' # console.log 'subscription_handler getStripeSubscriptions'
return @sendForbiddenError(res) unless req.user?.isAdmin() return @sendForbiddenError(res) unless req.user?.isAdmin()
subscriptions = [] stripeSubscriptions = []
createGetSubFn = (customerID, subscriptionID) => createGetSubFn = (customerID, subscriptionID) =>
(done) => (done) =>
stripe.customers.retrieveSubscription customerID, subscriptionID, (err, subscription) => stripe.customers.retrieveSubscription customerID, subscriptionID, (err, subscription) =>
# TODO: return error instead of ignore? # TODO: return error instead of ignore?
subscriptions.push(subscription) unless err stripeSubscriptions.push(subscription) unless err
done() done()
tasks = [] tasks = []
for subscription in req.body.subscriptions for subscription in req.body.subscriptions
tasks.push createGetSubFn(subscription.customerID, subscription.subscriptionID) tasks.push createGetSubFn(subscription.customerID, subscription.subscriptionID)
async.parallel tasks, (err, results) => async.parallel tasks, (err, results) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err
@sendSuccess(res, subscriptions) @sendSuccess(res, stripeSubscriptions)
getSubscribers: (req, res) -> getSubscribers: (req, res) ->
# console.log 'subscription_handler getSubscribers' # console.log 'subscription_handler getSubscribers'