overleaf/services/web/app/coffee/Features/Subscription/SubscriptionBackgroundTasks.coffee
Henry Oswald f2069c6208 converted all analytics to use new google analytics, removing mixpanel
and heap. Not tracking subscriptions or cancelations yet.
2014-03-08 19:00:26 +00:00

19 lines
870 B
CoffeeScript

async = require 'async'
logger = require 'logger-sharelatex'
SubscriptionUpdater = require("./SubscriptionUpdater")
SubscriptionLocator = require("./SubscriptionLocator")
module.exports = SubscriptionBackgroundJobs =
# TODO: Remove this one month after the ability to start free trials was removed
downgradeExpiredFreeTrials: (callback = (error, subscriptions)->) ->
SubscriptionLocator.expiredFreeTrials (error, subscriptions) =>
return callback(error) if error?
logger.log total_subscriptions:subscriptions.length, "downgraging subscriptions"
downgrades = []
for subscription in subscriptions
do (subscription) =>
downgrades.push (cb) =>
logger.log subscription: subscription, "downgrading free trial"
SubscriptionUpdater.downgradeFreeTrial(subscription, cb)
async.series downgrades, (error) -> callback(error, subscriptions)