Skip to content

Instantly share code, notes, and snippets.

@m00zi
Created June 14, 2018 09:23
Show Gist options
  • Save m00zi/684270387bad8ee22e24213ed0fdef63 to your computer and use it in GitHub Desktop.
Save m00zi/684270387bad8ee22e24213ed0fdef63 to your computer and use it in GitHub Desktop.
exports.deleteUser = (req, res, next) => {
var response;
console.log(req.params.user_id);
if (!req.params.user_id) {
response = {success: false, message: 'user id must be provided'};
res.send(response);
return;
}
console.log(req.params.user_id);
User.findByIdAndRemove(req.params.user_id, (err, user) => {
if (err) {
response = {success: false, message: 'Somthing went wrong'}
res.send(response);
return;
} else {
if (user) {
logger.info(`User ${user._id} , ${user.email} has been deleted from database`);
res.send({success: true});
return;
} else {
logger.info(`Something went wrong, when deleting user ${user._id} ${user.email}`);
res.send({success: false});
return;
};
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment