mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 14:02:41 +00:00
Fixed some edge cases on the api that were causing app crashes
This commit is contained in:
@@ -48,6 +48,8 @@ module.exports = function(app){
|
|||||||
//Edit Page
|
//Edit Page
|
||||||
app.get('/homebrew/edit/:id', function(req, res){
|
app.get('/homebrew/edit/:id', function(req, res){
|
||||||
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
HomebrewModel.find({editId : req.params.id}, function(err, objs){
|
||||||
|
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||||
|
|
||||||
var resObj = null;
|
var resObj = null;
|
||||||
var errObj = {text: "# oops\nCould not find the homebrew."}
|
var errObj = {text: "# oops\nCould not find the homebrew."}
|
||||||
if(objs.length){
|
if(objs.length){
|
||||||
@@ -73,16 +75,18 @@ module.exports = function(app){
|
|||||||
//Share Page
|
//Share Page
|
||||||
app.get('/homebrew/share/:id', function(req, res){
|
app.get('/homebrew/share/:id', function(req, res){
|
||||||
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
||||||
|
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||||
|
|
||||||
var resObj = null;
|
var resObj = null;
|
||||||
var errObj = {text: "# oops\nCould not find the homebrew."}
|
var errObj = {text: "# oops\nCould not find the homebrew."}
|
||||||
|
|
||||||
if(objs.length){
|
if(objs.length){
|
||||||
resObj = objs[0];
|
resObj = objs[0];
|
||||||
|
resObj.lastViewed = new Date();
|
||||||
|
resObj.views = resObj.views + 1;
|
||||||
|
resObj.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
resObj.lastViewed = new Date();
|
|
||||||
resObj.views = resObj.views + 1;
|
|
||||||
resObj.save();
|
|
||||||
|
|
||||||
vitreumRender({
|
vitreumRender({
|
||||||
page: './build/homebrew/bundle.dot',
|
page: './build/homebrew/bundle.dot',
|
||||||
globals:{},
|
globals:{},
|
||||||
@@ -103,10 +107,9 @@ module.exports = function(app){
|
|||||||
var PHBStyle = '<style>' + require('fs').readFileSync('./phb.standalone.css', 'utf8') + '</style>'
|
var PHBStyle = '<style>' + require('fs').readFileSync('./phb.standalone.css', 'utf8') + '</style>'
|
||||||
app.get('/homebrew/print/:id', function(req, res){
|
app.get('/homebrew/print/:id', function(req, res){
|
||||||
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
HomebrewModel.find({shareId : req.params.id}, function(err, objs){
|
||||||
if(err) return res.status(404).send();
|
if(err || !objs.length) return res.status(404).send('Could not find Homebrew with that id');
|
||||||
|
|
||||||
var resObj = null;
|
var resObj = null;
|
||||||
var errObj = {text: "# oops\nCould not find the homebrew."}
|
|
||||||
if(objs.length){
|
if(objs.length){
|
||||||
resObj = objs[0];
|
resObj = objs[0];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user