Skip to content

Commit

Permalink
fix(accounts): crash if user was deleted with active conversations #109
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Nov 21, 2018
1 parent 9a93998 commit 6ea0ad4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/controllers/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,17 @@ apiUsers.deleteUser = function(req, res) {
});
},
function(hasTickets, user, cb) {
if (hasTickets) {
//Disable if the user has tickets
var conversationSchema = require('../../../models/chat/conversation');
conversationSchema.getConversationsWithLimit(user._id, 10, function(err, conversations) {
if (err) return cb(err);

var hasConversations = _.size(conversations) > 0;
return cb(null, hasTickets, hasConversations, user);
});
},
function(hasTickets, hasConversations, user, cb) {
if (hasTickets || hasConversations) {
//Disable if the user has tickets or conversations
user.softDelete(function(err) {
if (err) return cb(err);

Expand Down

0 comments on commit 6ea0ad4

Please sign in to comment.