Skip to content

Commit 1749404

Browse files
committed
added update and delete
1 parent 56269d4 commit 1749404

2,337 files changed

Lines changed: 136994 additions & 66 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets" : [ "es2015"]
3+
}

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ app.use(function(req,res,next){
5454
res.locals.data = null;
5555
res.locals.title = null;
5656
res.locals.articles = null;
57+
res.locals.article = null;
58+
res.locals.typeOfBlog = null;
5759
res.locals.entryAdded = null;
5860
res.locals.message = null;
5961
res.locals.user = null;

controller/blog.server.controller.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ exports.create = function(req, res){
1515
res.redirect('/');
1616

1717
};
18+
exports.update = function(req, res, id){
19+
20+
var condition = {"_id" : id};
21+
var update = {
22+
"author": req.body.author,
23+
"date": req.body.date,
24+
"title": req.body.title,
25+
"article": req.body.article,
26+
"description": req.body.description,
27+
"email": req.body.email
28+
}
29+
30+
blogEntry.update(condition, update, function(err, numberAffected, rawResponse){
31+
if(err) res.render('error', {error: err.message, title: 'Oops! Something went wrong', user: req.user});
32+
//console.log(rawResponse);
33+
res.redirect('/');
34+
})
35+
};
1836

1937
exports.list = function(req, res){
2038
var query = blogEntry.find();
@@ -25,6 +43,15 @@ exports.list = function(req, res){
2543
});
2644
};
2745

46+
exports.delete = function(req, res, id){
47+
blogEntry.findByIdAndRemove({
48+
_id: req.params.id
49+
}, function(err, _) {
50+
if (err) return res.send(err)
51+
res.redirect('/');
52+
});
53+
};
54+
2855
exports.loadMore = function(req, res, n){
2956
var skinN = parseInt(n);
3057
var query = blogEntry.find({}).skip(skinN).limit(1);
@@ -33,7 +60,7 @@ exports.list = function(req, res){
3360
});
3461
};
3562

36-
exports.singleBlog = function(req, res, id){
63+
exports.singleBlog = function(req, res, id){
3764
var query = blogEntry.findOne({ '_id': id });
3865
query.exec(function(err, results){
3966
if(err){
@@ -45,6 +72,17 @@ exports.singleBlog = function(req, res, id){
4572
});
4673
};
4774

75+
exports.editBlog = function(req, res, id){
76+
var query = blogEntry.findOne({ '_id': id });
77+
query.exec(function(err, results){
78+
if(err){
79+
res.render('error', {error: err.message, title: 'Oops! Something went wrong', user: req.user})
80+
} else {
81+
res.render('articleEntryForm', {article: results, typeOfBlog: 'update', title : 'Edit article', user: req.user})
82+
}
83+
});
84+
};
85+
4886
// exports.getNote = function(req, res){
4987
// res.render('newnote',{title: 'Standup - New Note'});
5088
// };

node_modules/.bin/babel

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/babel-doctor

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/babel-external-helpers

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/babel-node

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/babylon

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/jsesc

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/json5

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)