Skip to content

Commit

Permalink
Fixed Bug #20
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Mar 30, 2017
1 parent 53632f1 commit f449cc8
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/controllers/api/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,29 @@ api_groups.updateGroup = function(req, res) {
};

/**
* Deletes a group object. <br> <br>
* Route: **[delete] /api/groups/:id**
* @api {delete} /api/v1/groups/:id Delete Group
* @apiName deleteGroup
* @apiDescription Deletes the given group by ID
* @apiVersion 0.1.6
* @apiGroup Group
* @apiHeader {string} accesstoken The access token for the logged in user
*
* @apiExample Example usage:
* curl -X DELETE -H "accesstoken: {accesstoken}" -l http://localhost/api/v1/groups/:id
*
* @todo revamp to support access token
* @param {object} req Express Request
* @param {object} res Express Response
* @return {JSON} Success/Error Json Object
* @apiSuccess {boolean} success If the Request was a success
* @apiSuccess {object} error Error, if occurred
*
* @apiError InvalidPostData The data was invalid
* @apiErrorExample
* HTTP/1.1 400 Bad Request
{
"error": "Invalid Post Data"
}
*/
api_groups.deleteGroup = function(req, res) {
var id = req.params.id;
if (_.isUndefined(id)) return res.status(400).json({success: false, error:'Error: Invalid Group Id.'});
var returnData = {
success: true
};

async.series([
function(next) {
Expand All @@ -261,23 +270,19 @@ api_groups.deleteGroup = function(req, res) {
groupSchema.getGroupById(id, function(err, group) {
if (err) return next('Error: ' + err.message);

if (group.name.toLowerCase() === 'administrators') return next('Error: Unable to delete default Administrators group.');

group.remove(function(err, success) {
if (err) return next('Error: ' + err.message);

return next(null, success);
});
});
}
], function(err, done) {
if (err) {
returnData.success = false;
returnData.error = err;

return res.json(returnData);
}
], function(err) {
if (err) return res.status(400).json({success: false, error: err});

returnData.success = true;
return res.json(returnData);
return res.json({success: true});
});
};

Expand Down

0 comments on commit f449cc8

Please sign in to comment.