aboutsummaryrefslogblamecommitdiff
path: root/controllers/post.js
blob: d879fcc94bfab29f8805c0dc618145086edb3232 (plain) (tree)


























                                                 



                                                                        


   
const Post = require('../models/post');

module.exports = {

  index(req, res) {
    Post.find().lean().exec((err, posts) => {
      res.render('home', {
        title: 'Home Page',
        home: true,
        posts: posts
      });
    });
  },

  create(req, res) {
    res.render('new-post', {
      title: 'Make A New Post',
      newPost: true
    });
  },

  store(req, res) {
    const newPost = new Post({
      'title': req.body.title,
      'text': req.body.text
    });
    newPost.save().then(() => res.redirect('/'));
  },

  destroy(req, res) {
    Post.findByIdAndRemove(req.params.id).then(() => res.redirect('/'));
  }

};