Skip to content

Commit

Permalink
fix(api): v2 removed ability to delete group if group had tickets
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 13, 2019
1 parent 38a4c85 commit 35dbef8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/controllers/api/v2/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

var apiUtils = require('../apiUtils')
var Ticket = require('../../../models/ticket')
var Group = require('../../../models/group')
var Department = require('../../../models/department')

Expand Down Expand Up @@ -90,11 +91,16 @@ apiGroups.delete = function (req, res) {
var id = req.params.id
if (!id) return apiUtils.sendApiError_InvalidPostData(res)

Group.deleteOne({ _id: id }, function (err, success) {
Ticket.countDocuments({ group: { $in: [id] } }, function (err, tickets) {
if (err) return apiUtils.sendApiError(res, 500, err.message)
if (!success) return apiUtils.sendApiError(res, 500, 'Unable to delete group. Contact your administrator.')
if (tickets > 0) return apiUtils.sendApiError(res, 400, 'Unable to delete group with tickets.')

return apiUtils.sendApiSuccess(res, { _id: id })
Group.deleteOne({ _id: id }, function (err, success) {
if (err) return apiUtils.sendApiError(res, 500, err.message)
if (!success) return apiUtils.sendApiError(res, 500, 'Unable to delete group. Contact your administrator.')

return apiUtils.sendApiSuccess(res, { _id: id })
})
})
}

Expand Down

0 comments on commit 35dbef8

Please sign in to comment.