text: const router = require('express').Router();
  const { Post, User, Comment } = require('../../models');
  const sequelize = require('../../config/connection');
  const withAuth = require('../../utils/auth');
  
  router.get('/', (req, res) => {
      Post.findAll({
          attributes: ['id', 'post_title', 'post_content', 'created_at'],
          order: [['created_at', 'DESC']],
          include: [{
              model: User,
              attributes: ['username']
          },
          {
              model: Comment,
              attributes: ['id', 'comment', 'postid', 'userid', 'created_at'],
              include: {
                  model: User,
                  attributes: ['username']
              }
          }
          ]
      })
          .then(dbPostData => res.json(dbPostData.reverse()))
          .catch(err => {
              res.status(500).json(err);
          });
  
  });
  router.get('/:id', (req, res) => {
      Post.findOne({
          where: {
              id: req.params.id
          },
          attributes: ['id', 'post_content', 'post_title', 'created_at'],
          include: [{
              model: User,
              attributes: ['username']
          },
          {
              model: Comment,
              attributes: ['id', 'comment', 'postid', 'userid', 'created_at'],
              include: {
                  model: User,
                  attributes: ['username']
              }
          }
          ]
      })
          .then(dbPostData => {
              if (!dbPostData) {
                  res.status(404).json({ message: 'No post matching this ID' });
                  return;
              }
              res.json(dbPostData);
          })
          .catch(err => {
              res.status(500).json(err);
          });
  });
  
  router.post('/', withAuth, (req, res) => {
      Post.create({
          post_title: req.body.post_title,
          post_content: req.body.post_content,
          userid: req.session.userid
      })
          .then(dbPostData => res.json(dbPostData))
          .catch(err => {
              res.status(500).json(err);
          });
  });
  
  router.put('/:id', withAuth, (req, res) => {
      Post.update({
          post_title: req.body.post_title,
          post_content: req.body.post_content
      }, {
          where: {
              id: req.params.id
          }
      }).then(dbPostData => {
          if (!dbPostData) {
              res.status(404).json({ message: 'No post matching this ID' });
              return;
          }
          res.json(dbPostData);
      })
          .catch(err => {
              res.status(500).json(err);
          });
  });
  router.delete('/:id', withAuth, (req, res) => {
      Post.destroy({
          where: {
              id: req.params.id
          }
      }).then(dbPostData => {
          if (!dbPostData) {
              res.status(404).json({ message: 'No post matching this ID' });
              return;
          }
          res.json(dbPostData);
      }).catch(err => {
          res.status(500).json(err);
      });
  });
  
  module.exports = router;