Guest User

Untitled

a guest
Oct 28th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. module.exports.update = async function(req, res) {
  2. const salt = await bcrypt.genSaltSync(10)
  3. const password = await req.body.password
  4. const update = {
  5. name: req.body.name,
  6. username: req.body.username,
  7. roles: req.body.roles,
  8. password: bcrypt.hashSync(password, salt)
  9. }
  10.  
  11. if (req.file) {
  12. update.photoSrc = req.file.path
  13. }
  14.  
  15. try {
  16. const user = await User.findOneAndUpdate({
  17. where: {
  18. id: req.params.id,
  19. $set: update,
  20. new: true
  21. }
  22. })
  23. res.status(200).json(user)
  24. } catch(e) {
  25. errorHandler(res, e)
  26. }
  27. }
Add Comment
Please, Sign In to add comment