diff --git a/api/controllers/ObjReferenceController.js b/api/controllers/ObjReferenceController.js index 64bb4b2..8d78caf 100644 --- a/api/controllers/ObjReferenceController.js +++ b/api/controllers/ObjReferenceController.js @@ -6,6 +6,34 @@ */ module.exports = { - + + search: function(req, res) { + var word = req.param('query'), + refQuery = ObjReference.find(); + + if (word != undefined) + refQuery = ObjReference.find({ + where: { + or: [ + {team: word}, + {type: word}, + {bbApi: word}, + {id: word}, + ] + }, + sort: { + date: 1 + } + }); + + refQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + } + }; diff --git a/api/controllers/ObjRevisionController.js b/api/controllers/ObjRevisionController.js index 98dc699..4c21f03 100644 --- a/api/controllers/ObjRevisionController.js +++ b/api/controllers/ObjRevisionController.js @@ -6,6 +6,70 @@ */ module.exports = { - + + search: function(req, res) { + var word = req.param('query'), + revisionQuery = ObjRevision.find(); + + if (word != undefined) + revisionQuery = ObjRevision.find({ + where: { + or: [ + {obj: {jarvisId: {contains: word}}}, + {obj: {bbApi: {contains: word}}} + ] + }, + sort: { + date: 1 + } + }); + + revisionQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + }, + + jarvisid: function(req, res) { + var word = req.param('query'), + revisionQuery = ObjRevision.find(); + + if (word != undefined) + revisionQuery = ObjRevision.find({ + jarvisId: word, + sort: { date: 1} + }); + + revisionQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + }, + + bbapi: function(req, res) { + var word = req.param('query'), + revisionQuery = ObjRevision.find(); + + if (word != undefined) + revisionQuery = ObjRevision.find({ + bbApi: word, + sort: { date: 1} + }); + + revisionQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + } + }; diff --git a/api/controllers/UserActivityController.js b/api/controllers/UserActivityController.js index 30a8642..986c558 100644 --- a/api/controllers/UserActivityController.js +++ b/api/controllers/UserActivityController.js @@ -6,6 +6,77 @@ */ module.exports = { - + + search: function(req, res) { + var word = req.param('query'), + refQuery = UserActivity.find(); + + if (word != undefined) + refQuery = UserActivity.find({ + where: { + or: [ + {team: word}, + {username: word} + ] + }, + sort: { + date: 1 + } + }); + + refQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + }, + + oneteam: function(req, res) { + var teamQ = req.param('team'), + refQuery = UserActivity.find(); + + if (teamQ != undefined) + refQuery = UserActivity.find({ + team: teamQ, + sort: { + date: -1 + } + }); + + refQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + }, + + oneuser: function(req, res) { + var teamQ = req.param('team'), + usernameQ = req.param('username'), + refQuery = UserActivity.find(); + + if ((teamQ != undefined) && (usernameQ != undefined)) + refQuery = UserActivity.find({ + team: teamQ, + username: usernameQ, + sort: { + date: -1 + } + }); + + refQuery.limit(10).exec(function(err, items) { + if (err) { + res.send(400); + } else { + res.send(items); + } + }); + } + + }; diff --git a/config/policies.js b/config/policies.js index 046fc08..d23d009 100644 --- a/config/policies.js +++ b/config/policies.js @@ -45,6 +45,21 @@ module.exports.policies = { 'find': true, 'search': true, }, + 'objrevision': { + '*': 'sessionAuth', + 'search': true, + 'jarvisid': true, + 'bbapi': true, + }, + 'objreference': { + '*': 'sessionAuth', + 'search': true, + }, + 'useractivity': { + '*': 'sessionAuth', + 'oneteam': true, + 'oneuser': true, + }, /*************************************************************************** * * diff --git a/config/routes.js b/config/routes.js index 386ef89..7994816 100644 --- a/config/routes.js +++ b/config/routes.js @@ -48,5 +48,12 @@ module.exports.routes = { 'GET /nationality/search/:query': 'NationalityController.search', 'GET /flag/search/:query': 'FlagController.search', 'GET /prefix/search/:query': 'PrefixController.search', + 'GET /objreference/search/:query': 'ObjReferenceController.search', + 'GET /useractivity/search/:query': 'UserActivityController.search', + 'GET /useractivity/u/:team': 'UserActivityController.oneteam', + 'GET /useractivity/u/:team/:username': 'UserActivityController.oneuser', + + 'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid', + 'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi', };