Browse Source

Add route to get specific user

main
Haris Razis 4 years ago
parent
commit
9b5288ef20
  1. 9
      server/routes/user.js

9
server/routes/user.js

@ -8,12 +8,19 @@ const {requireAuth} = require('../middlewares/middleware');
const User = mongoose.model('User') const User = mongoose.model('User')
const {userUpdateSchema, guid} = require('../schemas/joi'); const {userUpdateSchema, guid} = require('../schemas/joi');
router.get('/api/user/:id',
requireAuth,
async (req, res) => {
const user = await User.findById(req.params.id);
user.password = '';
res.send(user);
});
router.put('/api/user/:id', router.put('/api/user/:id',
requireAuth, requireAuth,
celebrate(userUpdateSchema, guid), celebrate(userUpdateSchema, guid),
async (req, res) => { async (req, res) => {
const {username, email, password, newPassword} = req.body const {username, email, password, newPassword} = req.body
bcrypt.compare(password, req.user.password, async (err, isMatch) => { bcrypt.compare(password, req.user.password, async (err, isMatch) => {
if (err) if (err)
return res.status(400).json({errors: 'Password is wrong!'}); return res.status(400).json({errors: 'Password is wrong!'});

Loading…
Cancel
Save