overleaf/services/web/app/coffee/Features/Subscription/UserFeaturesUpdater.coffee
2016-02-19 12:27:32 +00:00

16 lines
592 B
CoffeeScript

Settings = require "settings-sharelatex"
logger = require("logger-sharelatex")
User = require('../../models/User').User
PlansLocator = require("./PlansLocator")
module.exports =
updateFeatures: (user_id, plan_code, callback = (err, features)->)->
conditions = _id:user_id
update = {}
plan = PlansLocator.findLocalPlanInSettings(plan_code)
logger.log user_id:user_id, features:plan.features, plan_code:plan_code, "updating users features"
update["features.#{key}"] = value for key, value of plan.features
User.update conditions, update, (err)->
callback err, plan.features