diff --git a/api/controllers/TagController.js b/api/controllers/TagController.js new file mode 100644 index 0000000..624d664 --- /dev/null +++ b/api/controllers/TagController.js @@ -0,0 +1,54 @@ +/** + * TagController + * + * @description :: Server-side logic for managing Tags + * @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers + */ + +module.exports = { + + list: function(req, res) { + var team = req.param('team'), + type = req.query.type, + format = req.query.format, + q = { + where: { team: team }, + sort: { name: 1 } + }; + + if (type != undefined) + q['where'] = { + $and: [ + { team: team }, + { relatedTo: { $in: [type] } } + ] + } + + page = ((req.query.page != undefined) ? +req.query.page : 1); + Tag.find(q).paginate({page: page, limit: 10}).exec(function(err, items) { + if (format == 'long') { + res.send(items); + } else { + var tags = []; + for (var ind in items) { + tags.push(items[ind].name); + } + res.send(tags); + } + }); + }, + + detail: function(req, res) { + var team = req.param('team'), + name = req.param('name'); + + Tag.findOne({team: team, name: name}).exec(function(err, item) { + if (item == undefined) + res.send({}); + else + res.send(item); + }); + } + +}; + diff --git a/api/models/Tag.js b/api/models/Tag.js new file mode 100644 index 0000000..f260b1c --- /dev/null +++ b/api/models/Tag.js @@ -0,0 +1,20 @@ +/** +* Tag.js +* +* @description :: TODO: You might write a short summary of how this model works and what it represents here. +* @docs :: http://sailsjs.org/#!documentation/models +*/ + +module.exports = { + connection: 'jarvisBlackboard', + attributes: { + + team: 'string', + name: 'string', + relatedTo: { + type: 'array' + } + + } +}; + diff --git a/config/env/development/connections.js b/config/env/development/connections.js index 02c9a87..e1102bb 100644 --- a/config/env/development/connections.js +++ b/config/env/development/connections.js @@ -2,7 +2,7 @@ module.exports.connections = { hackintoshMongo: { adapter: 'sails-mongo', - host: '10hackintosh', + host: '10.10.10.51', port: 27017, // user: 'username', // password: 'password', @@ -10,7 +10,7 @@ module.exports.connections = { }, jarvisBlackboard: { adapter: 'sails-mongo', - host: '10hackintosh', + host: '10.10.10.51', port: 27017, // user: 'username', // password: 'password', diff --git a/config/routes.js b/config/routes.js index 035ec1d..76f7f38 100644 --- a/config/routes.js +++ b/config/routes.js @@ -58,4 +58,7 @@ module.exports.routes = { 'GET /objrevision/jarvisid/:query': 'ObjRevisionController.jarvisid', 'GET /objrevision/bbapi/:query': 'ObjRevisionController.bbapi', + 'GET /tag/:team': 'TagController.list', + 'GET /tag/:team/:name': 'TagController.detail', + };