bouquins/routes/tag.js

29 lines
738 B
JavaScript
Raw Normal View History

2014-05-22 19:08:41 +00:00
var express = require('express');
var router = express.Router();
2014-05-25 12:15:29 +00:00
var paginate = require('../util/paginate');
2014-05-22 19:08:41 +00:00
2014-05-25 12:15:29 +00:00
/* All tags */
2014-05-22 19:08:41 +00:00
router.get('/', function(req, res) {
2014-05-25 12:15:29 +00:00
var query = 'SELECT * FROM tags LIMIT ? OFFSET ?';
var tags = new Array();
req.paginate = new paginate(req);
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, row) {
if (tags.length < req.paginate.perpage)
tags.push(row);
else
req.paginate.hasNext = true;
}, function(err) {
res.links(req.paginate.links());
res.json(tags);
});
});
/* Single tag */
router.get('/:id', function(req, res) {
req.db.get('SELECT * FROM tags WHERE id = ?', req.params.id, function(err, row) {
res.json(row);
});
2014-05-22 19:08:41 +00:00
});
module.exports = router;