const router = require('express').Router() const { User, Vote } = require('../db/models') module.exports = router router.get('/', async (req, res, next) => { try { const users = await User.findAll({ attributes: ['id', 'name'] }) res.send(users) } catch (err) { next(err) } }) router.get('/:id', async (req, res, next) => { try { const user = await User.findByPk(req.params.id, {attributes: ['id', 'name'], include: {model: Vote, attributes: ['id', 'userId','commentId', 'upvote', 'downvote']}}) res.json(user) } catch (err) { next(err) } }) router.get('/:id/votes', async (req, res, next) => { try { const user = await User.findByPk(req.params.id, {attributes: ['id', 'name'], include: {model: Vote, attributes: ['id', 'userId','commentId', 'upvote', 'downvote']}}) res.json(user.votes) } catch (err) { next(err) } })