0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-02 15:02:38 +00:00

Added in the admin page

This commit is contained in:
Scott Tolksdorf
2016-01-06 20:04:45 -05:00
parent 25b53a7c24
commit 46186c0de2
11 changed files with 224 additions and 16 deletions

View File

@@ -1,12 +1,6 @@
var vitreumRender = require('vitreum/render');
var HomebrewModel = require('./homebrew.model.js').model;
module.exports = function(app){
@@ -49,6 +43,7 @@ module.exports = function(app){
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
var resEntry = objs[0];
resEntry.text = req.body.text;
resEntry.updatedAt = new Date();
resEntry.save(function(err, obj){
if(err) return res.status(500).send("Error while saving");
return res.status(200).send(obj);
@@ -56,6 +51,21 @@ module.exports = function(app){
});
});
app.get('/homebrew/remove/:id', function(req, res){
if(req.query && req.query.admin_key == process.env.ADMIN_KEY){
HomebrewModel.find({editId : req.params.id}, function(err, objs){
if(!objs.length || err) return res.status(404).send("Can not find homebrew with that id");
var resEntry = objs[0];
resEntry.remove(function(err){
if(err) return res.status(500).send("Error while removing");
return res.status(200).send();
})
});
}else{
return res.status(401).send('Access denied');
}
});
//Share Page
@@ -67,7 +77,9 @@ module.exports = function(app){
resObj = objs[0];
}
resObj.editId = null;
resObj.lastViewed = new Date();
resObj.views = resObj.views + 1;
resObj.save();
vitreumRender({
page: './build/homebrew/bundle.dot',

View File

@@ -1,5 +1,6 @@
var mongoose = require('mongoose');
var shortid = require('shortid');
var _ = require('lodash');
var HomebrewSchema = mongoose.Schema({
shareId : {type : String, default: shortid.generate},
@@ -7,15 +8,13 @@ var HomebrewSchema = mongoose.Schema({
text : {type : String, default : ""},
createdAt : { type: Date, default: Date.now },
updatedAt : { type: Date}
updatedAt : { type: Date},
lastViewed : { type: Date},
views : {type:Number, default:0}
});
//Schema Options
HomebrewSchema.pre('save', function(done) {
this.updatedAt = new Date();
done();
});
/*
HomebrewSchema.options.toJSON.transform = function (doc, ret, options) {