Skip to content

Commit

Permalink
Updated API for Mobile App
Browse files Browse the repository at this point in the history
Set ticket dropdown to click method
  • Loading branch information
polonel committed Jun 20, 2016
1 parent 30cf1ff commit 4c13783
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/controllers/api/v1/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,51 @@ api_tickets.get = function(req, res) {
});
};

/**
* @api {get} /api/v1/tickets/search/?search={searchString} Get Tickets by Search String
* @apiName search
* @apiDescription Gets tickets via search string
* @apiVersion 0.1.7
* @apiGroup Ticket
* @apiHeader {string} accesstoken The access token for the logged in user
*
* @apiExample Example usage:
* curl -H "accesstoken: {accesstoken}" -l http://localhost/api/v1/tickets/search/?search=searchString
*
* @apiSuccess {number} count Count of Tickets Array
* @apiSuccess {array} tickets Tickets Array
*
* @apiError InvalidRequest The data was invalid
* @apiErrorExample
* HTTP/1.1 400 Bad Request
{
"error": "Invalid Ticket"
}
*/
api_tickets.search = function(req, res) {
var searchString = req.query.search;

var ticketModel = require('../../../models/ticket');
var groupModel = require('../../../models/group');

async.waterfall([
function(callback) {
groupModel.getAllGroupsOfUserNoPopulate(req.user._id, function(err, grps) {
callback(err, grps);
});
},
function(grps, callback) {
ticketModel.getTicketsWithSearchString(grps, searchString, function(err, results) {
callback(err, results);
});
}
], function(err, results) {
if (err) return res.status(400).json({error: 'Error - ' + err.message});

return res.json({count: _.size(results), tickets: _.sortBy(results, 'uid').reverse()});
});
};

/**
* @api {post} /api/v1/tickets/create Create Ticket
* @apiName createTicket
Expand Down Expand Up @@ -293,6 +338,9 @@ api_tickets.update = function(req, res) {
if (!_.isUndefined(reqTicket.tags) && !_.isNull(reqTicket.tags))
ticket.tags = reqTicket.tags;

if (!_.isUndefined(reqTicket.assignee) && !_.isNull(reqTicket.assignee))
ticket.assignee = reqTicket.assignee;

ticket.save(function(err, t) {
if (err) return res.send(err.message);

Expand Down
28 changes: 28 additions & 0 deletions src/controllers/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,34 @@ api_users.removeApiKey = function(req, res) {
});
};

/**
* @api {get} /api/v1/getassignees Get Assignees
* @apiName getassignees
* @apiDescription Returns a list of assignable users
* @apiVersion 0.1.7
* @apiGroup User
* @apiHeader {string} accesstoken The access token for the logged in user
* @apiExample Example usage:
* curl -H "accesstoken: {accesstoken}" -l http://localhost/api/v1/users/getassignees
*
* @apiSuccess {boolean} success Successful?
* @apiSuccess {array} users Array of Assignees
*
* @apiError InvalidRequest The request was invalid
* @apiErrorExample
* HTTP/1.1 400 Bad Request
{
"error": "Invalid Request"
}
*/
api_users.getAssingees = function(req, res) {
userSchema.getAssigneeUsers(function(err, users) {
if (err) return res.status(400).json({error: 'Invalid Request'});

return res.json({success: true, users: users});
});
};

function StripUserFields(user) {
user.password = undefined;
user.accessToken = undefined;
Expand Down
50 changes: 50 additions & 0 deletions src/models/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,56 @@ ticketSchema.statics.getTicketsByRequester = function(userId, callback) {
return q.exec(callback);
};

ticketSchema.statics.getTicketsWithSearchString = function(grps, search, callback) {
if (_.isUndefined(grps) || _.isUndefined(search)) return callback("Invalid Post Data - TicketSchema.GetTicketsWithSearchString()", null);

var self = this;

var tickets = [];

async.parallel([
function(callback) {
var q = self.model(COLLECTION).find({group: {$in: grps}, deleted: false, $where: '/^' + search + '.*/.test(this.uid)'})
.populate('owner assignee type tags')
.deepPopulate(['group', 'group.members', 'group.sendMailTo', 'comments', 'comments.owner', 'history.owner', 'subscribers']);
q.exec(function(err, results) {
if (err) return callback(err);
tickets.push(results);

return callback(null);
});
},
function(callback) {
var q = self.model(COLLECTION).find({group: {$in: grps}, deleted: false, subject: { $regex: search, $options: 'i'}})
.populate('owner assignee type tags')
.deepPopulate(['group', 'group.members', 'group.sendMailTo', 'comments', 'comments.owner', 'history.owner', 'subscribers']);
q.exec(function(err, results) {
if (err) return callback(err);
tickets.push(results);

return callback(null);
});
},
function(callback) {
var q = self.model(COLLECTION).find({group: {$in: grps}, deleted: false, issue: { $regex: search, $options: 'i'}})
.populate('owner assignee type tags')
.deepPopulate(['group', 'group.members', 'group.sendMailTo', 'comments', 'comments.owner', 'history.owner', 'subscribers']);
q.exec(function(err, results) {
if (err) return callback(err);
tickets.push(results);

return callback(null);
});
}
], function(err) {
if (err) return callback(err, null);

var t = _.uniq(_.flatten(tickets), function(i){ return i.uid; });

return callback(null, t);
});
};

/**
* Gets tickets that are overdue
* @memberof Ticket
Expand Down
4 changes: 3 additions & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function mainRoutes(router, middleware, controllers) {
router.get('/api/v1/logout', middleware.api, controllers.api.logout);
router.post('/api/v1/devices/settoken', middleware.api, controllers.api.devices.setDeviceToken);
router.get('/api/v1/tickets', middleware.api, controllers.api.tickets.get);
router.get('/api/v1/tickets/search', middleware.api, controllers.api.tickets.search);
router.post('/api/v1/tickets/create', middleware.api, controllers.api.tickets.create);
router.get('/api/v1/tickets/types', middleware.api, controllers.api.tickets.getTypes);
router.post('/api/v1/tickets/addtag', middleware.api, controllers.api.tickets.addTag);
Expand Down Expand Up @@ -136,6 +137,7 @@ function mainRoutes(router, middleware, controllers) {
router.get('/api/v1/users', middleware.api, controllers.api.users.getWithLimit);
router.post('/api/v1/users/create', middleware.api, controllers.api.users.create);
router.get('/api/v1/users/notificationCount', middleware.api, controllers.api.users.notificationCount);
router.get('/api/v1/users/getassignees', middleware.api, controllers.api.users.getAssingees);
router.get('/api/v1/users/:username', middleware.api, controllers.api.users.single);
router.put('/api/v1/users/:username', middleware.api, controllers.api.users.update);
router.put('/api/v1/users/:username/updatepreferences', middleware.api, controllers.api.users.updatePreferences);
Expand Down Expand Up @@ -253,7 +255,7 @@ function allowCrossDomain(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');

if (req.method === 'OPTIONS') {
res.send(200);
res.sendStatus(200);
} else {
next();
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/tickets.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<div class="pagination uk-float-left">
<ul class="button-group uk-float-left">
<li class="pagination relative">
<div class="right" data-uk-dropdown="{pos: 'bottom-right'}" aria-haspopup="true" aria-expanded="false">
<div class="right" data-uk-dropdown="{pos: 'bottom-right', mode: 'click'}" aria-haspopup="true" aria-expanded="false">
<a href="#" class="btn no-ajaxy" data-notifications="ticket-actions" style="border-radius: 3px;"><i class="fa fa-large fa-tasks"></i></a>
<div class="uk-dropdown uk-dropdown-xsmall uk-dropdown-bottom">
<ul class="uk-nav">
Expand Down

0 comments on commit 4c13783

Please sign in to comment.