text: const router = require('express').Router();
  const { User, Post, Comment, Vote } = require('../../models');
  
  // GET all API users - /api/users
  router.get('/', (req, res) => {
      // Access our User model and run .findAll() method)
      User.findAll({
          attributes: { exclude: ['password'] }
      })
          .then(dbUserData => res.json(dbUserData))
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // GET one API user - /api/users/1
  router.get('/:id', (req, res) => {
      User.findOne({
          // ask TA if this structure makes sense?
          attributes: { exclude: ['password'] },
          where: {
              id: req.params.id
          },
          include: [
              {
                  model: Post,
                  attributes: ['id', 'title', 'post_url', 'created_at']
              },
              {
                  model: Comment,
                  attributes: ['id', 'comment_text', 'created_at'],
                  include: {
                      model: Post,
                      attributes: ['title']
                  }
              },
              {
                  model: Post,
                  attributes: ['title'],
                  through: Vote,
                  as: 'voted_posts'
              },
          ]
      })
          .then(dbUserData => {
              if (!dbUserData) {
                  res.status(404).json({ message: 'No user found with this id' });
                  return;
              }
              res.json(dbUserData);
          })
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // POST /api/users
  router.post('/', (req, res) => {
      // expects {username: 'Lernantino', email: 'lernantino@gmail.com', password: 'password1234'}
      User.create({
          username: req.body.username,
          email: req.body.email,
          password: req.body.password
      })
          .then(dbUserData => {
              req.session.save(() => {
                  req.session.user_id = dbUserData.id;
                  req.session.username = dbUserData.username;
                  req.session.loggedIn = true;
  
                  res.json(dbUserData);
              });
          })
  });
  
  router.post('/login', (req, res) => {
      // expects {email: 'lernantino@gmail.com', password: 'password1234'}
      User.findOne({
          where: {
              email: req.body.email
          }
      }).then(dbUserData => {
          if (!dbUserData) {
              res.status(400).json({ message: 'No user with that email address!' });
              return;
          }
          res.json({ user: dbUserData });
  
          // Verify user
          const validPassword = dbUserData.checkPassword(req.body.password);
          if (!validPassword) {
              res.status(400).json({ message: 'Incorrect password!' });
              return;
          }
  
          req.session.save(() => {
              // declare session variables
              req.session.user_id = dbUserData.id;
              req.session.username = dbUserData.username;
              req.session.loggedIn = true;
              res.json({ user: dbUserData, message: 'You are now logged in!' });
          });
      });
  });
  
  
  
  // PUT /api/users/1
  router.put('/:id', (req, res) => {
      // expects {username: 'Lernantino', email: 'lernantino@gmail.com', password: 'password1234'}
  
      // if req.body has exact key/value pairs to match the model, you can just use `req.body` instead
      User.update(req.body, {
          individualHooks: true,
          where: {
              id: req.params.id
          }
      })
          .then(dbUserData => {
              if (!dbUserData[0]) {
                  res.status(404).json({ message: 'No user found with this id' });
                  return;
              }
              res.json(dbUserData);
          })
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // DELETE /api/users/1
  router.delete('/:id', (req, res) => {
      User.destroy({
          where: {
              id: req.params.id
          }
      })
          .then(dbUserData => {
              if (!dbUserData) {
                  res.status(404).json({ message: 'No user found with this id' });
                  return;
              }
              res.json(dbUserData);
          })
          .catch(err => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  module.exports = router;