İş İlanı Oluştur
// APP.JS
app.get("/createPost", function(req, res) {
if (req.user) {
res.render("createPost")
} else {
res.render("login")
}
})
app.post("/createPost", function(req, res) {
const id = req.user.id
User.findById(id, function(err, foundUser) {
const newPost = new Post({
title: req.body.postTitle,
content: req.body.postContent,
postedBy: id
});
newPost.save(function(err) {
if (err)
console.log(err);
});
foundUser.posts.push(newPost)
foundUser.save(function(err) {
if (err) {
console.log(err)
}
res.redirect('/')
})
})
})
app.get("/posts", function(req, res) {
Post.find({}, function(err, posts) {
res.render("posts", {
posts: posts
});
});
});Last updated