text: const router = require('express').Router();
  const { User, Post, Comment } = require('../models');
  const sequelize = require('../config/connection');
  const withAuth = require('../utils/auth');
  
  // Route to render all posts
  router.get('/',withAuth, (req, res) => {
      Post.findAll({
          where: {
              user_id: req.session.user_id
          },
          attributes: [
              'id',
              'title',
              'content',
              'created_at'
          ],
          include: [
              {
                  model: Comment,
                  attributes: [
                      'id',
                      'comment_text',
                      'user_id',
                      'post_id',
                      'created_at'
                  ],
                  include: {
                      model: User,
                      attributes: ['username']
                  }
              },
              {
                  model: User,
                  attributes: ['username']
              }
          ]
      })
          .then(dbPostData => {
              const posts = dbPostData.map(post => post.get({ plain: true }));
              res.render('dashboard', { posts, loggedIn: true });
          })
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // Route to render edits to the dashboard
  router.get('/edit/:id', withAuth, (req, res) => {
      Post.findOne({
          where: {
              id: req.params.id
          },
          attributes: [
              'id',
              'title',
              'content',
              'created_at'
          ],
          include: [
              {
                  model: Comment,
                  attributes: [
                      'id',
                      'comment_text',
                      'user_id',
                      'post_id',
                      'created_at'
                  ],
                  include: {
                      model: User,
                      attributes: ['username']
                  }
              },
              {
                  model: User,
                  attributes: ['username']
              }
          ]
      })
          .then(dbPostData => {
              if (!dbPostData) {
                  res.status(404).json({ message: "No post found that matches that id." });
                  return;
              }
              const post = dbPostData.get({ plain: true });
              res.render('edit-post', { post, loggedIn: true });
          })
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // route to render a new post
  router.get('/new', (req, res) => {
      if (!req.session.loggedIn) {
          res.redirect('/');
          return;
      }
      res.render('new-post');
  });
  
  module.exports = router;