mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
22 lines
997 B
CoffeeScript
22 lines
997 B
CoffeeScript
|
async = require 'async'
|
||
|
logger = require 'logger-sharelatex'
|
||
|
SubscriptionUpdater = require("./SubscriptionUpdater")
|
||
|
SubscriptionLocator = require("./SubscriptionLocator")
|
||
|
AnalyticsManager = require("../Analytics/AnalyticsManager")
|
||
|
|
||
|
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"
|
||
|
AnalyticsManager.trackFreeTrialExpired subscription.admin_id
|
||
|
SubscriptionUpdater.downgradeFreeTrial(subscription, cb)
|
||
|
async.series downgrades, (error) -> callback(error, subscriptions)
|
||
|
|