const router = require('express').Router(); const { authenticate } = require('../auth/authenticate'); const Users = require('../users/usersModel'); router.get('/:id', authenticate, (req, res) => { Users.findUserById(req.params.id) .then(users => { res.status(200).json(users); }) .catch(err => res.send(err)); }); router.put('/:id', authenticate, async (req, res) => { Users.updateUser(req.params.id, req.body) .then(user => { if (user) { res.status(200).json(user); } else { res.status(404).json({ message: 'The user could not be found' }); } }) .catch(err => res.status(500).json({ message: 'Error updating the user' })); }); router.delete("/:id", (req, res) => { Users.removeUser(req.params.id) .then(data => res.status(200).json(data)) .catch(err => res.json(err)); }); module.exports = router;