You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
/** |
|
* 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); |
|
// TODO: find a way to rank it, so it's easier to tag |
|
Tag.find(q).paginate({page: page, limit: 20}).exec(function(err, items) { |
|
if (format == 'long') { |
|
res.send(items); |
|
} else { |
|
var tags = []; |
|
for (var ind in items) { |
|
var text = items[ind].name; |
|
tags.push({id: text, name: text}); |
|
} |
|
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); |
|
}); |
|
} |
|
|
|
}; |
|
|
|
|