Skip to content

Commit

Permalink
chore(apiv1): added get ticket count with custom query
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Apr 11, 2019
1 parent 984a4c7 commit 2286538
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/controllers/api/v1/routes.js
Expand Up @@ -66,6 +66,13 @@ module.exports = function (middleware, router, controllers) {
router.get('/api/v1/tickets/count/topgroups', apiv1, apiCtrl.tickets.getTopTicketGroups)
router.get('/api/v1/tickets/count/topgroups/:top', apiv1, apiCtrl.tickets.getTopTicketGroups)
router.get('/api/v1/tickets/count/topgroups/:timespan/:top', apiv1, apiCtrl.tickets.getTopTicketGroups)
router.get(
'/api/v1/tickets/count/group/:id',
apiv1,
isAgentOrAdmin,
canUser('tickets:view'),
apiCtrl.tickets.getCountByGroup
)
router.get('/api/v1/tickets/stats', apiv1, apiCtrl.tickets.getTicketStats)
router.get('/api/v1/tickets/stats/group/:group', apiv1, apiCtrl.tickets.getTicketStatsForGroup)
router.get('/api/v1/tickets/stats/user/:user', apiv1, apiCtrl.tickets.getTicketStatsForUser)
Expand Down
42 changes: 42 additions & 0 deletions src/controllers/api/v1/tickets.js
Expand Up @@ -242,6 +242,48 @@ apiTickets.getByGroup = function (req, res) {
})
}

apiTickets.getCountByGroup = function (req, res) {
var groupId = req.params.id
if (!groupId) return res.status(400).json({ success: false, error: 'Invalid Group Id' })
if (_.isUndefined(req.query.type) || _.isUndefined(req.query.value))
return res.status(400).json({ success: false, error: 'Invalid QueryString' })

var type = req.query.type
var value = req.query.value
// var limit = req.query.limit ? Number(req.query.limit) : -1
// var page = req.query.page ? Number(req.query.page) : 0

var ticketSchema = require('../../../models/ticket')

var obj = {
// limit: limit,
// page: page
}

switch (type.toLowerCase()) {
case 'status':
obj.status = [Number(value)]
ticketSchema.getCountWithObject([groupId], obj, function (err, count) {
if (err) return res.status(500).json({ success: false, error: err.message })

return res.json({ success: true, count: count })
})
break
case 'tickettype':
obj.filter = {
types: [value]
}
ticketSchema.getCountWithObject([groupId], obj, function (err, count) {
if (err) return res.status(500).json({ success: false, error: err.message })

return res.json({ success: true, count: count })
})
break
default:
return res.status(400).json({ success: false, error: 'Unsupported type query' })
}
}

/**
* @api {get} /api/v1/tickets/search/?search={searchString} Get Tickets by Search String
* @apiName search
Expand Down

0 comments on commit 2286538

Please sign in to comment.