sipp11
9 years ago
4 changed files with 79 additions and 2 deletions
@ -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); |
||||
}); |
||||
} |
||||
|
||||
}; |
||||
|
@ -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' |
||||
} |
||||
|
||||
} |
||||
}; |
||||
|
Loading…
Reference in new issue