Browse Source

Policy & add UserActivity route

master
sipp11 9 years ago
parent
commit
69c6dd0e6d
  1. 30
      api/controllers/UserActivityController.js
  2. 4
      api/models/UserActivity.js
  3. 2
      config/policies.js
  4. 1
      config/routes.js

30
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) { oneteam: function(req, res) {
var teamQ = req.param('team'), var teamQ = req.param('team'),
_options = {}, _options = {},
@ -49,7 +75,7 @@ module.exports = {
if (err) if (err)
res.send(400); 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) { if (err) {
res.send(400); res.send(400);
} else { } else {
@ -76,7 +102,7 @@ module.exports = {
if (err) if (err)
res.send(400); 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) { if (err) {
res.send(400); res.send(400);
} else { } else {

4
api/models/UserActivity.js

@ -17,8 +17,8 @@ module.exports = {
verb: 'string', verb: 'string',
team: 'string', team: 'string',
date: 'datetime', date: 'datetime',
jarvisId: { model: 'ObjReference' }, jarvisId: 'string',
revision: { model: 'ObjRevision' } revision: { model: 'ObjRevision' },
} }
}; };

2
config/policies.js

@ -59,6 +59,8 @@ module.exports.policies = {
}, },
'useractivity': { 'useractivity': {
'*': 'sessionAuth', '*': 'sessionAuth',
'findOne': true,
'jarvisid': true,
'oneteam': true, 'oneteam': true,
'oneuser': true, 'oneuser': true,
}, },

1
config/routes.js

@ -52,6 +52,7 @@ module.exports.routes = {
'GET /useractivity/search/:query': 'UserActivityController.search', 'GET /useractivity/search/:query': 'UserActivityController.search',
'GET /useractivity/u/:team': 'UserActivityController.oneteam', 'GET /useractivity/u/:team': 'UserActivityController.oneteam',
'GET /useractivity/u/:team/:username': 'UserActivityController.oneuser', 'GET /useractivity/u/:team/:username': 'UserActivityController.oneuser',
'GET /useractivity/jarvisid/:query': 'UserActivityController.jarvisid',
'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid', 'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid',
'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi', 'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi',

Loading…
Cancel
Save