overleaf/services/web/app/coffee/Features/BetaProgram/BetaProgramHandler.coffee

32 lines
942 B
CoffeeScript
Raw Normal View History

2016-06-07 06:15:56 -04:00
User = require("../../models/User").User
logger = require 'logger-sharelatex'
metrics = require("metrics-sharelatex")
2016-06-07 06:15:56 -04:00
module.exports = BetaProgramHandler =
optIn: (user_id, callback=(err)->) ->
User.findById user_id, (err, user) ->
if err
logger.err {err, user_id}, "problem adding user to beta"
return callback(err)
metrics.inc "beta-program.opt-in"
user.betaProgram = true
user.save (err) ->
if err
logger.err {err, user_id}, "problem adding user to beta"
return callback(err)
return callback(null)
2016-06-08 10:11:39 -04:00
optOut: (user_id, callback=(err)->) ->
User.findById user_id, (err, user) ->
if err
logger.err {err, user_id}, "problem removing user from beta"
return callback(err)
metrics.inc "beta-program.opt-out"
user.betaProgram = false
user.save (err) ->
if err
logger.err {err, user_id}, "problem removing user from beta"
return callback(err)
return callback(null)