2014-02-12 10:23:40 +00:00
|
|
|
User = require("../../models/User").User
|
2014-04-04 14:47:27 +00:00
|
|
|
NewsletterManager = require "../Newsletter/NewsletterManager"
|
2014-02-12 10:23:40 +00:00
|
|
|
ProjectDeleter = require("../Project/ProjectDeleter")
|
|
|
|
logger = require("logger-sharelatex")
|
2014-03-03 16:22:55 +00:00
|
|
|
SubscriptionHandler = require("../Subscription/SubscriptionHandler")
|
|
|
|
async = require("async")
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
deleteUser: (user_id, callback = ()->)->
|
|
|
|
if !user_id?
|
|
|
|
logger.err "user_id is null when trying to delete user"
|
|
|
|
return callback("no user_id")
|
|
|
|
User.findById user_id, (err, user)->
|
|
|
|
if err?
|
|
|
|
return callback(err)
|
2014-03-03 16:22:55 +00:00
|
|
|
logger.log user:user, "deleting user"
|
|
|
|
async.series [
|
|
|
|
(cb)->
|
|
|
|
NewsletterManager.unsubscribe user, cb
|
|
|
|
(cb)->
|
|
|
|
ProjectDeleter.deleteUsersProjects user._id, cb
|
|
|
|
(cb)->
|
2015-01-02 10:37:59 +00:00
|
|
|
SubscriptionHandler.cancelSubscription user, cb
|
2014-03-03 16:22:55 +00:00
|
|
|
(cb)->
|
|
|
|
user.remove cb
|
|
|
|
], (err)->
|
2014-02-12 10:23:40 +00:00
|
|
|
if err?
|
2014-03-03 16:22:55 +00:00
|
|
|
logger.err err:err, user_id:user_id, "something went wrong deleteing the user"
|
|
|
|
callback err
|