diff --git a/api/controllers/UserActivityController.js b/api/controllers/UserActivityController.js index e85c9a3..f880115 100644 --- a/api/controllers/UserActivityController.js +++ b/api/controllers/UserActivityController.js @@ -34,6 +34,32 @@ module.exports = { }); }, + jarvisid: function(req, res) { + var word = req.param('query'), + _options = {}, + _count, query; + + if (word != undefined) { + _options['jarvisId'] = word; + } + _options['sort'] = {date: -1}; + + query = UserActivity.find(_options); + page = ((req.query.page != undefined) ? +req.query.page : 1); + UserActivity.count(_options).exec(function(err, total) { + if (err) + res.send(400); + + query.paginate({page: page, limit: 10}).populate('revision').exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send({count: total, results: items}); + } + }); + }); + }, + oneteam: function(req, res) { var teamQ = req.param('team'), _options = {}, @@ -49,7 +75,7 @@ module.exports = { if (err) res.send(400); - query.paginate({page: page, limit: 10}).populate('jarvisId').exec(function(err, items) { + query.paginate({page: page, limit: 10}).populate('revision').exec(function(err, items) { if (err) { res.send(400); } else { @@ -76,7 +102,7 @@ module.exports = { if (err) res.send(400); - query.paginate({page: page, limit: 10}).populate('jarvisId').exec(function(err, items) { + query.paginate({page: page, limit: 10}).populate('revision').exec(function(err, items) { if (err) { res.send(400); } else { diff --git a/api/models/UserActivity.js b/api/models/UserActivity.js index 5b544cc..1e3d637 100644 --- a/api/models/UserActivity.js +++ b/api/models/UserActivity.js @@ -17,8 +17,8 @@ module.exports = { verb: 'string', team: 'string', date: 'datetime', - jarvisId: { model: 'ObjReference' }, - revision: { model: 'ObjRevision' } + jarvisId: 'string', + revision: { model: 'ObjRevision' }, } }; diff --git a/config/policies.js b/config/policies.js index fc804ba..fd97152 100644 --- a/config/policies.js +++ b/config/policies.js @@ -59,6 +59,8 @@ module.exports.policies = { }, 'useractivity': { '*': 'sessionAuth', + 'findOne': true, + 'jarvisid': true, 'oneteam': true, 'oneuser': true, }, diff --git a/config/routes.js b/config/routes.js index 7994816..6423290 100644 --- a/config/routes.js +++ b/config/routes.js @@ -52,6 +52,7 @@ module.exports.routes = { 'GET /useractivity/search/:query': 'UserActivityController.search', 'GET /useractivity/u/:team': 'UserActivityController.oneteam', 'GET /useractivity/u/:team/:username': 'UserActivityController.oneuser', + 'GET /useractivity/jarvisid/:query': 'UserActivityController.jarvisid', 'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid', 'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi',