SubscriptionBackgroundTasks.coffee 870 B

12345678910111213141516171819
  1. async = require 'async'
  2. logger = require 'logger-sharelatex'
  3. SubscriptionUpdater = require("./SubscriptionUpdater")
  4. SubscriptionLocator = require("./SubscriptionLocator")
  5. module.exports = SubscriptionBackgroundJobs =
  6. # TODO: Remove this one month after the ability to start free trials was removed
  7. downgradeExpiredFreeTrials: (callback = (error, subscriptions)->) ->
  8. SubscriptionLocator.expiredFreeTrials (error, subscriptions) =>
  9. return callback(error) if error?
  10. logger.log total_subscriptions:subscriptions.length, "downgraging subscriptions"
  11. downgrades = []
  12. for subscription in subscriptions
  13. do (subscription) =>
  14. downgrades.push (cb) =>
  15. logger.log subscription: subscription, "downgrading free trial"
  16. SubscriptionUpdater.downgradeFreeTrial(subscription, cb)
  17. async.series downgrades, (error) -> callback(error, subscriptions)