flosight-api/app/controllers/blocks.js
2014-01-08 11:56:36 -03:00

70 lines
1.1 KiB
JavaScript

'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block');
//, _ = require('lodash');
/**
* Find block by hash ...
*/
exports.block = function(req, res, next, hash) {
Block.fromHash(hash, function(err, block) {
if (err) return next(err);
if (!block) return next(new Error('Failed to load block ' + hash));
req.block = block;
next();
});
};
/**
* Show block
*/
exports.show = function(req, res) {
res.jsonp(req.block);
};
/**
* List of blocks at HomePage
*/
exports.last_blocks = function(req, res) {
Block.find().limit(7).exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};
/**
* List of blocks by date
*/
exports.list = function(req, res) {
var findParam = {};
if (req.query.blockDate) {
findParam = {};
}
Block
.find(findParam)
.limit(5)
.exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};