Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports.update = async function(req, res) {
- const salt = await bcrypt.genSaltSync(10)
- const password = await req.body.password
- const update = {
- name: req.body.name,
- username: req.body.username,
- roles: req.body.roles,
- password: bcrypt.hashSync(password, salt)
- }
- if (req.file) {
- update.photoSrc = req.file.path
- }
- try {
- const user = await User.findOneAndUpdate({
- where: {
- id: req.params.id,
- $set: update,
- new: true
- }
- })
- res.status(200).json(user)
- } catch(e) {
- errorHandler(res, e)
- }
- }
Add Comment
Please, Sign In to add comment