move logic to model code

This commit is contained in:
Girish Ramakrishnan
2016-06-02 22:25:48 -07:00
parent 13a1213b0d
commit 097d23c412
4 changed files with 44 additions and 17 deletions

View File

@@ -125,16 +125,11 @@ function remove(req, res, next) {
if (req.user.id === req.params.userId) return next(new HttpError(403, 'Not allowed to remove yourself.'));
user.get(req.params.userId, function (error, userObject) {
user.remove(req.params.userId, auditSource(req), function (error) {
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user'));
if (error) return next(new HttpError(500, error));
user.remove(userObject, auditSource(req), function (error) {
if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(204));
});
next(new HttpSuccess(204));
});
}