sleep-tracker-backend/services/users/usersRouter.js
ruihildt 77a4c28757 Fix dailyAverages query on session update & test
- Add dailyAverages seeds
- Start implementing testing
2019-08-02 01:18:56 +02:00

33 lines
827 B
JavaScript

const router = require('express').Router();
const Users = require('../users/usersModel');
// TODO: add validation
router.get('/:id', (req, res) => {
Users.findUserById(req.params.id)
.then(users => {
res.status(200).json(users);
})
.catch(err => res.send(err));
});
router.put('/:id', 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(() => res.status(500).json({ message: 'Error updating the user' }));
});
router.delete("/:id", (req, res) => {
Users.removeUser(req.params.id)
.then(() => res.status(200).json({ message: 'The user was successfully deleted.'}))
.catch(err => res.json(err));
});
module.exports = router;